Last active
January 29, 2018 16:43
-
-
Save johnstevenson/12348144c498e9545cd73ea01435c904 to your computer and use it in GitHub Desktop.
PHP Windows opcache-xdebug crash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!getenv('RESTART_TEST')) { | |
showExtensionInfo(); | |
putenv('RESTART_TEST=1'); | |
putenv('PHP_INI_SCAN_DIR='); | |
$iniFiles = getIniFiles(); | |
$tmpIni = writeTmpIni($iniFiles); | |
$args = array_merge([PHP_BINARY, '-c', $tmpIni], $_SERVER['argv']); | |
$command = implode(' ', array_map('escapeshellarg', $args)); | |
passthru($command); | |
} else { | |
echo 'Process restarted', PHP_EOL; | |
showExtensionInfo(); | |
} | |
function getIniFiles() | |
{ | |
$iniFiles = [strval(php_ini_loaded_file())]; | |
if ($scanned = php_ini_scanned_files()) { | |
$iniFiles = array_merge($iniFiles, array_map('trim', explode(',', $scanned))); | |
} | |
if (empty($iniFiles[0])) { | |
array_shift($iniFiles); | |
} | |
return $iniFiles; | |
} | |
function writeTmpIni(array $iniFiles) | |
{ | |
$tmpIni = sys_get_temp_dir().DIRECTORY_SEPARATOR.'tmp.ini'; | |
$content = ''; | |
$regex = '/^\s*(zend_extension\s*=.*xdebug.*)$/mi'; | |
$replace = in_array('--keep-xdebug', $_SERVER['argv']) ? '$1' : ';$1'; | |
foreach ($iniFiles as $file) { | |
$data = preg_replace($regex, $replace, file_get_contents($file)); | |
$content .= $data.PHP_EOL; | |
} | |
if (defined('PHP_WINDOWS_VERSION_BUILD')) { | |
if (in_array('--fix', $_SERVER['argv'])) { | |
$content .= 'opcache.enable_cli=0'.PHP_EOL; | |
} | |
} | |
file_put_contents($tmpIni, $content); | |
return $tmpIni; | |
} | |
function showExtensionInfo() | |
{ | |
if (extension_loaded('zend opcache')) { | |
$opcache = 'extension: opcache loaded'; | |
$opcache .= ', opcache.enable_cli='.ini_get('opcache.enable_cli'); | |
} else { | |
$opcache = 'extension: opcache not loaded'; | |
} | |
if (extension_loaded('xdebug')) { | |
$xdebug = 'extension: xdebug loaded'; | |
} else { | |
$xdebug = 'extension: xdebug not loaded'; | |
} | |
echo $opcache, PHP_EOL, $xdebug, PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test script for Windows bug: https://bugs.php.net/bug.php?id=75886
Usage
Config: Enable opcache and xdebug extensions, set
opcache.enable_cli=1