运行并忘记php中的系统调用

发布于 2024-08-12 12:31:58 字数 475 浏览 1 评论 0原文

所以我试图从我的 php 代码执行一些脚本。它位于 blah.php 页面中,

<?php
     // ....
     // just basic web site that allows upload of file...
?>

在里面我使用系统调用,

if (system("blah.pl arg1") != 0)
{
   print "error\n";
}
else
{
   print "working on it..you will receive e-mail at completion\n";
}

效果很好,但它会等到它完成后再打印它的工作。 我知道我从 php 调用 perl 脚本不是一个拼写错误。

我怎样才能开始程序执行并让它在后台完成。 blah.pl 脚本处理电子邮件通知。

有人吗?

谢谢我很感激

So I am trying to execute some script from my php code. That lives in page blah.php

<?php
     // ....
     // just basic web site that allows upload of file...
?>

Inside I use system call

if (system("blah.pl arg1") != 0)
{
   print "error\n";
}
else
{
   print "working on it..you will receive e-mail at completion\n";
}

Works great but it waits until it completes until it prints working on it.
I am aware that I am calling perl script from php not a typo.

How can I just start program execution and let it complete in background.
The blah.pl script handles e-mail notification.

Anyone?

Thanks I appreciate it

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

穿透光 2024-08-19 12:31:58

来自 system 函数文档:

注意:如果使用此函数启动程序,为了使其继续在后台运行,程序的输出必须重定向到文件或另一个输出流。如果不这样做将导致 PHP 挂起,直到程序执行结束。

只需重定向 Perl 脚本的输出,PHP 就应该能够运行,而无需等待脚本完成。

system("blah.pl arg1 > /dev/null 2>&1 &");

From system function documentation:

Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

Simply redirect the output of your Perl script and PHP should be able to run without having to wait for the script to finish.

system("blah.pl arg1 > /dev/null 2>&1 &");
李不 2024-08-19 12:31:58

您可以添加一个&符号来在后台生成该进程吗?

if (system("blah.pl arg1 &") != 0)

Can you add an ampersand to spawn the process in the background?

if (system("blah.pl arg1 &") != 0)
习惯成性 2024-08-19 12:31:58

您可能可以使用 popen 函数

http://www.php.net/manual /en/function.popen.php

You could probably use the popen function

http://www.php.net/manual/en/function.popen.php

纵性 2024-08-19 12:31:58

由于所有 PHP 命令行函数都等待结果 - 我建议您有一个单独的页面来调用电子邮件脚本。

换句话说,使用 cURL 或文件包装器向 email.php 页面(或其他页面)发送请求,这允许您在接收结果之前关闭连接。所以这个过程看起来像这样。

        page_running.php
        |
    cURL call to (email.php?arg1=0)
        |           |
final output        email.php
                    |
                    calls system("blah.pl arg1")

Since all the PHP command line functions wait for a result - I recommend that you have a separate page to call the emailer script.

In other words, send a request to the email.php page (or whatever) using cURL or the file wrappers which allows you to close the connection before receiving a result. So the process will look something like this.

        page_running.php
        |
    cURL call to (email.php?arg1=0)
        |           |
final output        email.php
                    |
                    calls system("blah.pl arg1")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文