spajak
spajak

Reputation: 603

PHP 5.6 Segmentation fault: 11 (anonnymous function, recursion)

What is wrong with this code? It works when $it = 1000 but fails with Segmentation fault: 11 when $it > 8000. There is neither a script timeout nor memory exhausted. Setting high memory_limit makes no difference.

$it = 10000;
$middleware = function($chain) {
    $chain();
};

$chain = function() use (&$chain, $it, $middleware) {
    static $index = 0;
    if ($index++ < $it) {
        $middleware($chain);
    }
};

$chain();

My system is PHP 5.6.16 with the following extensions:

Core, date, ereg, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2,
calendar, ctype, dom, hash, fileinfo, filter, ftp, gd, gettext, SPL,
iconv, json, ldap, mbstring, session, standard, mysqlnd, pcntl,
mysqli, PDO, pdo_mysql, pdo_sqlite, Phar, posix, Reflection, mysql,
shmop, SimpleXML, soap, sockets, exif, sysvmsg, sysvsem, sysvshm,
tidy, tokenizer, wddx, xml, xmlreader, xmlrpc, xmlwriter, zip, curl,
gmp, igbinary, imap, intl, mcrypt, memcache, memcached, mongo, 
mssql, OAuth, pdo_dblib, pdo_pgsql, pgsql, propro, raphf, readline,  
redis, solr, ssh2, xsl, http, mhash, xdebug

Upvotes: 2

Views: 898

Answers (1)

VerteXVaaR
VerteXVaaR

Reputation: 805

Have you tried changing the PHP version? Anytime i get segmentation faults i switch to PHP 7.0 and suddenly there's an accurate error message. I fix the error and switch back to PHP 5.6 and it works again. Maybe your callback throws an exception and the error handler crashes.

Upvotes: 1

Related Questions