![](/img/trans.png)
[英]Populating $_SERVER when using popen to run a php script in background
[英]Can't Run a background PHP Script With Popen
我有一个需要在后台运行的PHP代码(没有cronjobs或类似选项)是完整的,但我只是不能在后台调用它。 我正在尝试以下方法:
$files = $_GET['files'];
$id = $_GET['id'];
pclose(popen("start /B D:\\server\\php\\php.exe D:\\server\\www\\whatever\\importat\\import.php?files=".$files."&id=".$id." 2>nul >nul", "r"));
但是它永远不会运行。 如果我手动运行import.php ,它将正常运行。
PS:我无法更改import.php。
救命?
我得到了解决方案:
我正在做的是在批处理中调用PHP并使用popen启动它:
$phpBatch = "progress_import_".$idImport.".bat";
$myPhp = fopen($phpBatch, "w") or die("Error opening file!");
$batchContent .= "@echo OFF \n";
$batchContent .= "\"D:\\path\\to\\php.exe\" D:\\path\\to\\progress_import.php ".$idImport." ".$_SESSION['numberFiles']." ";
pclose(popen("start /B D:\\path\\to\\".$phpBatch."", "r"));
在progress_import.php
我正在使用:
$id = $argv[1];
$numberFiles = $argv[2];
捕捉参数。
希望能对某人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.