Skip to content

Instantly share code, notes, and snippets.

@krakjoe
krakjoe / try-finally-auto-log
Created December 8, 2021 08:16
try-finally-auto
string(12) "Oh Exception"
Finally Foo::bar
Finally Foo::qux
Fatal error: Uncaught RuntimeException: Oh qux! in /opt/src/php-src/try-finally-auto.php:22
Stack trace:
#0 /opt/src/php-src/try-finally-auto.php(30): Foo->qux()
#1 {main}
thrown in /opt/src/php-src/try-finally-auto.php on line 22
@krakjoe
krakjoe / php-xz.patch
Created August 19, 2019 13:41
php-xz php7
diff --git a/config.m4 b/config.m4
index 90bbe66..e3ffe7c 100644
--- a/config.m4
+++ b/config.m4
@@ -1,47 +1,10 @@
dnl $Id$
dnl config.m4 for extension xz
-dnl Comments in this file start with the string 'dnl'.
-dnl Remove where necessary. This file will not work
@krakjoe
krakjoe / crawler.php
Last active October 11, 2023 19:07
parallel Futures, Channels (buffered, unbuffered, synchros), Events using parallel producer/consumer pattern
<?php
use \parallel\{Runtime, Future, Channel, Events};
/* usage php crawler.php [http://example.com] [workers=8] [limit=500] */
$page = $argv[1] ?: "https://blog.krakjoe.ninja"; # start crawling this page
$workers = $argv[2] ?: 8; # start this number of threads
$limit = $argv[3] ?: 500; # stop at this number of unique pages
$timeout = $argv[4] ?: 3; # socket timeout for producers
@krakjoe
krakjoe / example.php
Last active October 11, 2023 19:07
Executor Service with Parallel and Channels
<?php
use \parallel\{Runtime, Channel};
class ExecutorService {
public function __construct(int $workers, string $channel = __CLASS__, int $backlog = Channel::Infinite) {
if ($backlog == 0) {
/*
* execute() will block until a worker is ready
*/
@krakjoe
krakjoe / log.diff
Last active July 20, 2022 22:01
pcov vs xdebug comparison
--- pcov.log 2019-01-20 14:28:58.444851609 +0100
+++ xdebug.log 2019-01-20 14:25:27.607884120 +0100
@@ -1,8 +1,8 @@
-time php vendor/bin/phpunit --coverage-text --colors=never 2>&1 > pcov.log
+time php vendor/bin/phpunit --coverage-text --colors=never 2>&1 >xdebug.log
PHPUnit 7.5.2 by Sebastian Bergmann and contributors.
-Runtime: PHP 7.2.15-dev
+Runtime: PHP 7.2.15-dev with Xdebug 2.7.0beta2-dev
@krakjoe
krakjoe / document.php
Last active April 17, 2023 11:03
for generating stubs for a loaded extension
<?php
/*
usage: php document.php --ext name [--output document.txt]
*/
function prototype(Reflector $reflector) {
$elements = [];
switch (get_class($reflector)) {
case "ReflectionClass":
if ($reflector->isFinal()) {
@krakjoe
krakjoe / opcache.diff
Created April 14, 2017 10:21
7.1.0 ... 7.1.4 ext/opcache
diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c
index 77b02cc99f..38c2ecb124 100644
--- a/ext/opcache/Optimizer/block_pass.c
+++ b/ext/opcache/Optimizer/block_pass.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| Zend OPcache |
+----------------------------------------------------------------------+
- | Copyright (c) 1998-2016 The PHP Group |
+ | Copyright (c) 1998-2017 The PHP Group |
@krakjoe
krakjoe / mm.patch
Created January 22, 2017 18:58
gd mm
diff --git a/src/gdhelpers.c b/src/gdhelpers.c
index 20fff5c..a64278b 100644
--- a/src/gdhelpers.c
+++ b/src/gdhelpers.c
@@ -14,6 +14,33 @@
#define SEP_TEST (separators[*((unsigned char *) s)])
+static inline void* gd_malloc_wrapper(size_t size)
+{
@krakjoe
krakjoe / variance-correct-probably.patch
Last active November 14, 2016 10:21
variance corrections
diff --git a/Zend/tests/object_types/variance_in_param.phpt b/Zend/tests/object_types/variance_in_param.phpt
index bcc528e..cf28dd8 100644
--- a/Zend/tests/object_types/variance_in_param.phpt
+++ b/Zend/tests/object_types/variance_in_param.phpt
@@ -15,6 +15,7 @@ class Bar extends Foo {
var_dump(new Bar);
?>
--EXPECTF--
+Warning: Declaration of Bar::qux(Qux $qux) should be compatible with Foo::qux(object $object) in %s on line 10
object(Bar)#%d (0) {
@krakjoe
krakjoe / starfield.d
Created November 8, 2016 11:06
Starfield in D, uses krakjoe/dui (or any other 1:1 module)
import std.random;
import andlabs.libui;
struct Star {
double X;
double Y;
double V;
bool F;
double G;