[英]php cron jobs from cpanel is not working. No error in email
I have uploaded a simple cron.php with insert in mySQL database. 我已经在mySQL数据库中上传了一个带有插入的简单cron.php。
cron.php cron.php
#!/bin/bash
mysql --user=[myUsernameToDatabase] --password=[myPasswordToDatabase] --database=[myDatabaseName] --execute="INSERT INTO room (room_name,room_guid) VALUES ('test', 'testing')"
I have added this in cpanel -> Cron Jobs 我在cpanel-> Cron Jobs中添加了它
Common Settings: one minute 通用设置:一分钟
Command: /usr/bin/php -q /home/myUsername/public_html/cron.php
命令:
/usr/bin/php -q /home/myUsername/public_html/cron.php
I receive email every minute with the code I added in cron jobs -> Command and no error. 我每分钟都会收到一封电子邮件,其中包含我在cron作业->命令中添加的代码,没有错误。 But nothing is added in my database.
但是什么都没有添加到我的数据库中。
My test query works fine if I run it in my database 如果我在数据库中运行它,我的测试查询就可以正常工作
INSERT INTO room (room_name,room_guid) VALUES ('test', 'testar')
You're trying to run a bash
shell script as PHP
, which simply won't work. 您试图将
bash
shell脚本作为PHP
,但这根本行不通。 There are a few things you need to do before this can even have a chance of executing successfully: 您需要做几件事,然后才能成功执行:
1. Rename cron.php to cron.sh
2. DO NOT put the script in your `public_html` directory.
locate it somewhere not public (eg. /home/myUsername/scripts/).
3. Try using this in your crontab:
/bin/sh /home/myUsername/scripts/cron.sh 2>&1
At the very least this should get things in a better position to work properly. 至少这应该使事情更好地发挥作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.