Skip to content

Instantly share code, notes, and snippets.

View jpauli's full-sized avatar
🐍

jpauli jpauli

🐍
View GitHub Profile
@jpauli
jpauli / gist:8afec7c4fc2b38f8ff27
Created June 13, 2014 14:17
fallocate VS ftruncate demo
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
if (argc != 3) {
printf("Usage: allocate <1:ftruncate, 2:fallocate> <size> \n");
@jpauli
jpauli / gist:69ff64a8425e8fd2e24b
Created July 1, 2014 16:36
PHP fast-cgi pool balancer management script
#!/bin/bash
pool1=pool_1
pool2=pool_2
port1=8031
port2=8032
nbport1=0
nbport2=0
#! /usr/bin/env php
<?php
if ($argc != 2) {
exit(sprintf("Usage : %s <pid>\n", $argv[0]));
}
if (!file_exists("/proc/1/status")) {
exit("/proc/1/status does not exist, what OS are you running ?\n");
@jpauli
jpauli / gist:2158791
Created March 22, 2012 14:54
Simple PHP chat using nc
<?php
$p = proc_open("/bin/nc -l -p 11111", array (STDIN, array("pipe", "w"), array("file", "/dev/null", 'w')), $pipes);
while (1) {
$read = array($pipes[1]);
$write = $except = null;
stream_select($read, $write, $except, 2);
echo fgets($pipes[1]);
}
@jpauli
jpauli / gist:2471030
Created April 23, 2012 13:50
libmysql VS mysqlnd read-only resultset allocations with buffered queries (store mode)
---- libmysql in store result mode ----
206 1,035,035,700 24,367,728 24,177,686 190,042 0
99.22% (24,177,686B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->88.15% (21,479,147B) 0x52DD010: my_malloc (my_malloc.c:37)
| ->88.04% (21,452,640B) 0x52E0583: alloc_root (my_alloc.c:219)
| | ->44.60% (10,869,120B) 0x5307A1F: cli_read_rows (client.c:1416)
| | | ->44.60% (10,869,120B) 0x5305955: mysql_store_result (client.c:2957)
| | | | ->44.60% (10,869,120B) 0x53EF09: zif_mysqli_query (mysqli_nonapi.c:540)
| | | | ->44.60% (10,869,120B) 0x70186A: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:320)
@jpauli
jpauli / gist:2480585
Created April 24, 2012 15:25
Using mysqlnd stats to track development errors
<?php
class ComutoMysqli extends Mysqli
{
public function __destruct()
{
$stats = $this->get_connection_stats();
$this->close();
if($diff = $stats["rows_fetched_from_server_normal"] - ($stats["rows_fetched_from_client_normal_unbuffered"] + $stats["rows_fetched_from_client_normal_buffered"])) {
trigger_error("You didn't use *$diff* selected results, that's wasted!", E_USER_NOTICE);
}
@jpauli
jpauli / gist:2499452
Created April 26, 2012 13:11
mysqlnd read-only copy-on-write memory savings
julien@lapjpauli:/tmp$ valgrind /home/julien/php53mysqlnd/bin/php -dmemory_limit=-1 /home/julien/www/mysqlnd_POC/poc_mysqlnd.php 1000
initial memory ->86480 kB
resultSet stored ->229632 kB
query result saved ->234016 kB
query result freed ->234016 kB
resultSet freed ->134816 kB
Db closed ->134816 kB
==32226==
==32226== HEAP SUMMARY:
==32226== in use at exit: 0 bytes in 0 blocks
@jpauli
jpauli / gist:3236041
Created August 2, 2012 10:01
Save your I/Os, dont use open_basedir
$> strace php -r '@unlink("foo.bar");' 2>&1|grep 'foo.bar'
execve("/usr/bin/php", ["php", "-r", "@unlink(\"foo.bar\");"], [/* 17 vars */]) = 0
unlink("foo.bar") = -1 ENOENT (No such file or directory)
$> strace php -d open_basedir="./" -r '@unlink("foo.bar");' 2>&1|grep 'foo.bar'
typedef struct _hashtable {
uint nTableSize;
uint nTableMask;
uint nNumOfElements;
zend_bool persistent;
unsigned char nApplyCount;
zend_bool bApplyProtection;
ulong nNextFreeElement;
Bucket *pInternalPointer; /* Used for element traversal */
diff --git a/xdebug_var.c b/xdebug_var.c
index a59c4f5..c92d114 100644
diff --git a/xdebug_var.c b/xdebug_var.c
index a59c4f5..c92d114 100644
--- a/xdebug_var.c
+++ b/xdebug_var.c
@@ -434,6 +434,7 @@ void xdebug_var_export(zval **struc, xdebug_str *str, int level, int debug_zval,
case IS_OBJECT:
myht = Z_OBJPROP_PP(struc);