cron tab not working php

╄→гoц情女王★ 提交于 2019-12-13 11:28:46

问题


I added a cronjob by entering this command - crontab -e. I added the following tasks in that file-

*/5 * * * * /var/www/web/vendors/shells/aggregated_deals.php
*/5 * * * * /var/www/web/vendors/shells/deals.php

These are php scripts. after that i restarted the apache server,but these scripts are not executing. And syslog log file is empty. please help me to run this cron.


回答1:


I don't think that will run by itself - you need to run the scripts using the PHP interpreter, like this:

/usr/bin/php /var/www/web/vendors/shells/aggregated_deals.php

Note that your installation may have php elsewhere - use the command which php on the command line to find out the location.




回答2:


I don't think you can execute a PHP file by calling it like that, I always use a curl:

*/5 * * * * curl http://domain.com/page

Or I guess you could run it using the php command itself if you don't want to use the web server:

*/5 * * * * php /var/www/web/vendors/shells/aggregated_deals.php

What ever you type after the stars in the crontab rule will be the command execute against the system. If you run the command "/var/www/web/vendors/shells/aggregated_deals.php" in terminal I bet nothing happens...you need to invoke this as a PHP script.




回答3:


Why don't you call php-cli with the right user ?

*/5 * * * * www-data php /var/www/web/vendors/shells/aggregated_deals.php

OR

*/5 * * * * root /usr/bin/php /var/www/web/vendors/shells/aggregated_deals.php

Or something like that. Have you already installed php-cli ?




回答4:


First, you need to make sure that you have PHP CLI available. You can do it by running this:

$ php -v

If you see some sane output, then PHP CLI is available. Otherwise you'll need to install it. Installation depends on the distro you're using.

Second, if you want to run CLI scripts directly, you need to make them executable:

$ chmod +x /var/www/web/vendors/shells/aggregated_deals.php
$ chmod +x /var/www/web/vendors/shells/deals.php

Third, PHP CLI scripts are not related to apache and you don't need to restart it to make CLI scripts work.




回答5:


You need to tell the server to execute the files with PHP. Do all the stesps as described in Elnurs answer, and put these as your lines in cron:

*/5 * * * * php -f /var/www/web/vendors/shells/aggregated_deals.php > /tmp/my.log 2>&1
*/5 * * * * php -f /var/www/web/vendors/shells/deals.php > /tmp/my.log 2>&1

If that doesn't work you may need to include the entire path to PHP. I've also just added some lines to make the script log any output.




回答6:


You need to run it cake style... you must run

cake shellName shellParam

i your case it would be

cake aggregated_deals > /tmp/my.log
cake deals > /tmp/my.log 2>&1

this cake is in your cake folder, and you should be running it from your app folder... i am not sure how to do this from cron but that is what you have wrong...

This is asuming those scripts are valid cakeShells




回答7:


You need to tell the server to execute the files with PHP. Do all the stesps as described in Elnurs answer, and put these as your lines in cron:

*/5 * * * * php -f /var/www/web/vendors/shells/aggregated_deals.php > /tmp/my.log 2>&1
*/5 * * * * php -f /var/www/web/vendors/shells/deals.php > /tmp/my.log 2>&1

$ chmod +x /var/www/web/vendors/shells/aggregated_deals.php
$ chmod +x /var/www/web/vendors/shells/deals.php



回答8:


I know this is posting a long time after, but it looks like i'm not the only one.

Anyway my suggestion would be to add the path to the php in the cron line:

*/5 * * * * /usr/bin/php -f /var/www/web/vendors/shells/aggregated_deals.php > /tmp/my.log 2>&1
*/5 * * * * /usr/bin/php -f /var/www/web/vendors/shells/deals.php > /tmp/my.log 2>&1

Again make sure the permissions are good



来源:https://stackoverflow.com/questions/8008270/cron-tab-not-working-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!