简体   繁体   中英

Cron job to run php script

I've got a simple script that sends email if you refresh the page. I need it to run every week. I setup a command in CPanel to run that script

php /home/site/public_html/test/sendmail.php

But it does not work. Hosting support says I setup cron in CP correctly.

I wander if I need any intermediate script to run sendmail.php. Thank you for your help in advance.

您很可能需要将cron调用扩展到/usr/bin/php /home/site/public_html/test/sendmail.php ,因为系统找不到php可执行文件的路径。

You can also add a PHP shebang to the script and run it like a normal shell script without php -f :

#!/usr/bin/php
<?php
//your code

?>

To get the PHP path, use this code: <?php echo PHP_BINDIR, PHP_EOL; ?> <?php echo PHP_BINDIR, PHP_EOL; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM