通过 PHP 的 Unix `at` 命令
这是我创建新 at
作业的代码...system('echo \'php -f /path/to/my/php/file.php\' | at 1700');
我认为这很简单并且可以工作,但是唉,什么也没有发生了!
当我运行 echo \'php -f /path/to/my/php/file.php\' |在 1700
通过 ssh 一切都按预期工作。
这是权限问题吗?即 PHP 不允许创建新的 at
作业?
Here's my code to create a new at
job...system('echo \'php -f /path/to/my/php/file.php\' | at 1700');
I thought this would be simple and would just work but alas, nothing happens!
When I run echo \'php -f /path/to/my/php/file.php\' | at 1700
via ssh everything works as expected.
Is this a permissions problem? I.e PHP isn't allowed to create new at
jobs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅供参考,您必须确保您可以从 PHP 脚本执行系统命令。
许多服务器都禁用了此功能。
但是,如果您想重新打开此功能,我相信您可以在 php.ini 文件中执行此操作,则必须将 safe_mode 关闭。
当允许将用户提供的数据传递给此函数时,请使用 escapeshellarg() 或 escapeshellcmd() 以确保用户无法欺骗系统执行任意命令。
如果使用此函数启动程序,为了使其继续在后台运行,必须将程序的输出重定向到文件或另一个输出流。如果不这样做将导致 PHP 挂起,直到程序执行结束。
注意:启用安全模式后,您只能执行 safe_mode_exec_dir 中的文件。出于实际原因,当前不允许在可执行文件的路径中包含 .. 组件。
Just FYI you have to make sure that you are allowed to execute system commands from your PHP scripts.
A lot of servers have this feature disabled.
However, if you want to turn this back on I believe you can do so in the php.ini file, you would have to turn safe_mode to off.
When allowing user-supplied data to be passed to this function, use escapeshellarg() or escapeshellcmd() to ensure that users cannot trick the system into executing arbitrary commands.
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.
Note: When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable.