See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Executing PHP from crontab

General Tech Bugs & Fixes

Max. 2000 characters



( 5 months ago )

I am utilizing crontab to execute a PHP file as follows:

0 4 * * * /opt/lampstack/php/bin/php /opt/lampstack/apache2/htdocs/tests/test.php

I am pretty sure that the file itself is working properly because if I execute /opt/lampstack/php/bin/php /opt/lampstack/apache2/htdocs/tests/test.php in command line I get the expected results.

In the cron log I can see that it is being called at the specified time, but the php file doesn't run (the php code is just one line that writes to a log file). I thought that maybe it has something to do with user permissions so I tried forcing it to be executed as root (by putting root between the time and /opt/lamp...) but still no luck.

Any words of wisdom?




( 5 months ago )

You could try to specify the path to the php.ini file with the -c switch and also use the -f switch to indicate the file to be executed.

0 4 * * * /opt/lampstack/php/bin/php -c /etc/php.ini -f /opt/lampstack/apache2/htdocs/tests/test.php

You might also want to turn on display_errors and error_reporting

But I also agree with the other responses in that it sounds like an issue with permissions to the log file itself. If you have a global error_log parameter set you can try to echo something out with error_log() in your code.

what's your interest