Reputation: 481
I want set up a cronjob for php script for every 2minutes in my ubuntu machine for this i have found the below link for reference but i am getting following error and i am not getting it how to resolve this error.
Link for reference to set cronjob
https://askubuntu.com/questions/177971/how-can-i-set-up-a-php-script-to-run-via-cron
First error: when i run a php script using command line i have got this error Fatal error: Call to undefined function mysql_connect() in /opt/lampp/htdocs/ezypayzy/cronjob.php on line 2.But when i run this script on browser it is working fine.i dont know how to solve this.
Command for php script:php /opt/lampp/htdocs/ezypayzy/cronjob.php
Second error: when i run a cronjob command on terminal it shows me this error
bash: */2: No such file or directory
Cronjob command:*/2 * * * * /usr/local/bin/php
/opt/lampp/htdocs/ezypayzy/cronjob.php
Upvotes: 4
Views: 2409
Reputation: 16495
If you are executing the same file and getting different output via shell and your browser, it's most likely you have different versions of PHP installed. Which is why you are getting undefined function mysql_connect()
because, you are referencing php 5.5.0+
to run your cronjob.
The solution is to first check where php is installed.
$ whereis php
Then try to check the versions using php -v
and /usr/local/bin/php -v
If all is okay, and you have php 5.5.0
or above, you can simple remove mysql_
functions and use instead mysqli/PDO.
At the end, your path should be like this.
*/2 * * * * /usr/local/bin/php /path/to/cronjob.php
Upvotes: 2