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 / 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 / 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 / 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 / SnapshotCommand.php
Created July 11, 2019 20:26
An example Laravel app command to create and load database snapshots using S3
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
class SnapshotCommand extends Command
{
@ralphschindler
ralphschindler / AuthServiceProvider.php
Last active April 5, 2019 09:04
Laravel 5.8 Policy Guesser For Using "Models" Directory
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
@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';
@ralphschindler
ralphschindler / database-column-ordering.md
Last active November 2, 2017 15:02
Ralph's Database Column Organization

Ralph's Database Column Organization

TLDR:

  1. primary key columns (e.g. id)
  2. foreign key columns (e.g. other_id)
  3. row qualifying columns (e.g. status)
  4. entity identification columns (e.g. name, title, slug, base_url)
  5. non-string-based entity attribute columns (e.g. rating, is_admin)
  6. string-based entity attribute columns (e.g. short_description, description, notes)
@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)...