简体   繁体   English

无法使用Popen运行后台PHP脚本

[英]Can't Run a background PHP Script With Popen

I have a PHP code that needs to run in background (no cronjobs or similar options) that is complete, but I just can't call it in the background. 我有一个需要在后台运行的PHP代码(没有cronjobs或类似选项)是完整的,但我只是不能在后台调用它。 I'm trying the following: 我正在尝试以下方法:

$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"));

But it' never runs. 但是它永远不会运行。 If I go and run import.php manually, it works without fail. 如果我手动运行import.php ,它将正常运行。

PS: I can't change the import.php. PS:我无法更改import.php。

Help? 救命?

I got the solution: 我得到了解决方案:

What I am doing is calling the PHP inside a batch and launching it using popen: 我正在做的是在批处理中调用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"));

And inside the progress_import.php i'm using: progress_import.php我正在使用:

$id = $argv[1];
$numberFiles = $argv[2];

To catch the parameters. 捕捉参数。

Hope that helps someone. 希望能对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM