无法运行 PHP cron 脚本

Cannot get PHP cron script to run(无法运行 PHP cron 脚本)
本文介绍了无法运行 PHP cron 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个需要每分钟运行一次的 PHP 脚本.我已经确保脚本可以从命令行运行,并且我使用绝对路径来避免任何环境问题:

I have a PHP script that I need to run every minute. I have made sure that the script works from the command line, and I'm using absolute paths to avoid any environment issues:

/usr/bin/php -q /var/www/myapp/services/myservice.php

从命令行以 root 用户身份手动运行它可以正常工作,正如我从脚本写入的日志文件中看到的那样.可以肯定的是,该脚本也具有执行权限.

Manually running that as root from the command line works fine, as I can see from the log file that my script writes to. To be sure, the script has execute permissions as well.

但是,当在 cron 中放置相同的命令时:

However, when placing the same exact command in a cron:

* * * * * /usr/bin/php -q /var/www/myapp/services/myservice.php

它没有运行,或者至少看起来是这样.我也尝试将输出重定向到另一个日志文件:

It does not run or at least it appear so. I've tried redirecting the output to another log file too:

* * * * * /usr/bin/php -q /var/www/myapp/services/myservice.php >> /mylog.log 2>&1

还是没有.我没有任何迹象表明正在运行的脚本.我想它没有,但我不知道还要寻找什么.我什至重新启动了 cron 守护进程.

Still nothing. I have no indication whatsoever of the script being ran. I guess it doesn't, but I have no idea what else to look for. I even restarted the cron daemon.

我知道在 StackOverflow 上也有类似的问题,但没有一个答案对我来说是一个解决方案.这简直让我发疯了,我将不胜感激任何帮助.

I know there are similar questions on StackOverflow, but none of the answers turned out to be a solution for me. This is literally driving me crazy, I will greatly appreciate any help.

推荐答案

我找到了解决我的问题的方法:

I found a solution for my issue:

https://serverfault.com/questions/97828/php-from-command-line-path-problems/97881#97881

事实证明我需要 cd(更改目录)到脚本目录中,然后调用它.令人惊讶,因为我使用的是绝对路径,但它有效.感谢那些花时间回复的人.

It turns out I needed to cd (change directory) into the script dir and then call it. Surprising, since I'm using absolute paths, but it works. Thanks to those who have taken the time to respond.

这篇关于无法运行 PHP cron 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)