Skip to content

Instantly share code, notes, and snippets.

View ralphschindler's full-sized avatar

Ralph Schindler ralphschindler

View GitHub Profile
@ralphschindler
ralphschindler / use-ffi-to-write-to-file-via-low-level-standard-c-library-functions.php
Last active May 6, 2024 20:33
PHP Write to stdout via /proc/1/fd/1 using FFI (useful for logging inside a container)
<?php
// php can't write directly to a non-regular-file due to the php filesystem
// abstraction in place. But, we can use direct calls to the low level standard
// library to achieve this.
// normally, you should use the dio extension:
// - https://pecl.php.net/package/dio
// - https://github.com/php/pecl-system-dio/tree/master
@ralphschindler
ralphschindler / README.md
Last active May 1, 2024 19:14
Docker For Mac Host Address Alias To Enable PHP XDebug (10.254.254.254 Trick)

Docker (Mac) De-facto Standard Host Address Alias

This launchd script will ensure that your Docker environment on your Mac will have 10.254.254.254 as an alias on your loopback device (127.0.0.1). The command being run is ifconfig lo0 alias 10.254.254.254.

Once your machine has a well known IP address, your PHP container will then be able to connect to it, specifically XDebug can connect to it at the configured xdebug.remote_host.

Installation Of IP Alias (This survives reboot)

Copy/Paste the following in terminal with sudo (must be root as the target directory is owned by root)...

@ralphschindler
ralphschindler / xdebug.sh
Created February 9, 2024 16:20
Enable/Disable Xdebug Via CLI Script
#!/bin/bash
QUIET=0
restart_php_fpm () {
if [ $QUIET -eq 1 ]; then
sv restart php-fpm > /dev/null
else
sv restart php-fpm
fi
@ralphschindler
ralphschindler / example.php
Created October 24, 2012 23:18
Zend\Db\Sql\Select example usage
<?php
use Zend\Db\Sql\Select;
// basic table
$select0 = new Select;
$select0->from('foo');
// 'SELECT "foo".* FROM "foo"';
@ralphschindler
ralphschindler / Dockerfile
Created September 8, 2021 13:39
Build php xdebug from scratch in a Docker container, with laravel app
FROM ubuntu:20.10
RUN mkdir /app
WORKDIR /app
RUN apt-get update && DEBIAN_FRONTEND=noninteractive \
apt-get install -qqy --no-install-recommends \
ca-certificates \
valgrind \
@ralphschindler
ralphschindler / .php_cs.dist
Created April 20, 2021 14:24
Generic PHP-CS-Fixer Rules
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->notName('.php_cs.dist');
return (new PhpCsFixer\Config)
->setFinder($finder)
->setRules([
@ralphschindler
ralphschindler / StringIsLengthRule.php
Last active April 19, 2021 19:21
Custom Dynamic Validation Rules for Laravel 5.5+
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class StringIsLengthRule implements Rule
{
protected $length;
protected $message = 'The string must be greater than the length';

The 231 New Orleanians On Github

(Followers / Following in last column)

Ralph Schindler
@ralphschindler
ralphschindler / Dockerfile
Last active December 15, 2020 01:39
Dockerfile for setting up PHP 8 and xdebug to demonstrate an issue
FROM ubuntu:20.10
RUN mkdir /app
WORKDIR /app
RUN apt-get update && DEBIAN_FRONTEND=noninteractive \
apt-get install -qqy --no-install-recommends \
ca-certificates \
valgrind \
@ralphschindler
ralphschindler / aop-uow-change-tracking.php
Last active November 22, 2020 04:03
A aop based Unit Of Work prototype/example with minimal code
<?php
/**
* Foo is an Entity
*/
class Foo
{
protected $bar = 'original';
public function getBar()