Unix/Windows,安装后台进程?来自 PHP 代码

发布于 2025-01-05 04:49:19 字数 844 浏览 2 评论 0原文

所以我从 http://php.net/manual/en/function.exec 找到了一个函数.php

function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
    pclose(popen("start /B ". $cmd, "r")); 
}
else {
    exec($cmd . " > /dev/null &");  
}
}

Windows 用法:

pclose(popen('start /B php path/to/background_cron.php', 'r'));

Unix 用法:

exec('php path/to/background_cron.php >> path/to/background_error.log &')

但是当调用这些行时,实际上什么也没有发生(等待 5 左右分钟后)。我做错了什么吗?在激活这些行之前,我有一个 file_exists 检查我的 path/to/background_cron.php 是否存在,如果不存在,它将返回错误。

在实时unix服务器上,所有文件夹权限都设置为所有者、组、公共(0755)的写入、读取、执行,并且文件权限设置为所有者、组、公共(644)的读取。 unix 命令运行后,background_log 变为空,它创建 4 个新的空行 (\n),但不返回任何期望

So I found a function from http://php.net/manual/en/function.exec.php

function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
    pclose(popen("start /B ". $cmd, "r")); 
}
else {
    exec($cmd . " > /dev/null &");  
}
}

Windows Usage:

pclose(popen('start /B php path/to/background_cron.php', 'r'));

Unix Usage:

exec('php path/to/background_cron.php >> path/to/background_error.log &')

But when these lines are called nothing actually happens (after waiting 5 or so minutes). Am I doing something wrong? prior to these lines being activated I have a file_exists checking if my path/to/background_cron.php exists and it if it doesn't it will return a error.

On the live unix server all the folder permissions are set to write,read,execute for owner,group,public (0755) and file permissions are set to read for owner,group,public (644). The background_log comes up empty after the unix command runs, it creates 4 new blank lines (\n) but doesn't return any expections

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

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

发布评论

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

评论(1

夜深人未静 2025-01-12 04:49:19

Windows 中有点奇怪的一件事是,由于网络服务器以不同的用户身份运行,因此它在自己的用户空间(而不是您的桌面)中启动应用程序。

该进程可能正在启动,但不在您的进程列表中 - 请为所有用户检查它。另外,请检查事件日志,以防它尝试运行但抛出异常。

另一种可能是 Web 用户没有执行命令的权限 - 查看应用程序池正在以谁的身份运行,并检查他们对这些应用程序的权限文件夹。

请小心,不要通过允许网络服务器运行任意代码来创建安全漏洞。

One thing that's a little odd in windows is that since the webserver is running as a different user, it launches apps in its own userspace - not your desktop.

It's possible the process is launching and isn't in your process list - check it for all users. Also, check the event log in case it's trying to run but throwing an exception

Another possibility is that the web user doesn't have permissions to execute the command- Have a look at who the app pool is running as and check their permissions to those folders.

Be careful you don't create security holes by allowing the webserver to run arbitrary code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文