如何使用 exec() 函数启动和停止 PHP 开发服务器?我需要这样做才能自动化我的 BDD 测试。
这将停止我的脚本的执行:
echo exec('php -S localhost:8000');
所以我需要一种方法从 PHP 启动服务器并能够继续执行我的测试。然后我还需要一种方法来阻止 PHP。
这有效:
private function _startDevelopmentServer($pidfile)
{
$cmd = 'cd ../../public && php -S 127.0.0.1:8027 index.php';
$outputfile = '/dev/null';
shell_exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
sleep(1);
}
private function _killDevelopmentServer($pidfile)
{
if (file_exists($pidfile)) {
$pids = file($pidfile);
foreach ($pids as $pid) {
shell_exec('kill -9 ' . $pid);
}
unlink($pidfile);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)