Skip to content

Instantly share code, notes, and snippets.

<?php
define('TIME_NOW', time());
define('DS', DIRECTORY_SEPARATOR);
define('BASE_PATH', strtr(__DIR__, '\\', '/'));
clearstatcache();
$pathimpl = function() {
return BASE_PATH . '/' . ltrim(strtr(implode(DS, func_get_args()), '\\', '/'), '/');
@RomanStone
RomanStone / PECL.Events.Server.example.php
Created May 8, 2019 13:31
PHP Events Simple Hello World Server Example
<?php
$addr = '127.0.0.1';
$port = 10080;
$host = 'localhost';
function hello_world($args = array()) {
$OS = PHP_OS; //strtolower(substr(PHP_OS, 0, 3)) == 'win';
$phpversion = phpversion();
@RomanStone
RomanStone / PHPServer.example.php
Last active April 25, 2019 01:48
An example of pure PHP Server (non-block, socket_select)
<?php
$addr = '127.0.0.1';
$port = 10080;
// Use: curl -vv "http://127.0.0.1:10080/"
// 0 prints dots in infinite response (on client's side), for concurrent test
// 1 close connection after server/client negotiation
@RomanStone
RomanStone / index.php
Last active December 20, 2020 20:38
Serving media files for A/Video Playback "pseudo chunked" transfer encoding
<?php
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('html_errors', 0);
ini_set('output_buffering', 0);
ini_set('zlib.output_compression', 0);
ini_set('implicit_flush', 1);
ini_set('ignore_user_abort', 1);