php/cron question..


hi all,

if i set a php script to run via cron, and in that php script i include another script…does the included script get executed too?

Colin :)


If you inlude() a script, it should run as long as it’s syntactically correct.

On that note, however, I don’t know if you can run a PHP script via cron.

For cron jobs you are better off using a shell script.

Good luck


yes, it does

one way to run a php script via cron is if you have lynx and your script can be accessed via the web, to do this enter this in your crontab…

lynx -dump

That will work just as if you opened it in your web browser


I think my response should been more of WHY you would want to run a php script as a cronjob.

You are displaying an HTML page (via php) for no one to see. Moreover, it seems like a waste of resources. You access Lynx to display a page (that noone sees), you access PHP which is accessed thorugh the webserver (apache?). The only real reason I can think of to run a PHP script that no one needs to see the output (directly) is perhaps to do some updating of files or maybe a database. This means someother resources like mySql being used. In either case a typical bash shell script (or perl or some other shell scripting) would seem to be more appropriate to that task.

Just my 2 cents…


Actually, you don’t even need to use lynx to do so. You can simply call the php interpreter directly in the cron (unless remote, but even there, you could do it using ssh).

/usr/local/bin/php /home/joe/script.php

It will actually have the same permissions as the user running it. The nice part is that you don’t have to give those permissions to your web server.

The other solution is to create an executable directly:

echo "Hello World!n";

Just make sure the script has execute permission.

PHP works jsut fine for shell scripts. One of the huge advantage is that you will be able to use the libraries you coded for your website. It also has a much better syntax than bash anyway.


Well, I guess I learned something new today.

I certainly can see the advantages of using php, but I was unaware that you could run it like that.

Knowing that may help me with other tasks.

Thanks Bane (I guess you aren’t the “All Knowing” for nothing.)


That’s only the result of reading way too much documentation and experimenting over 5 years, but I don’t know everything yet, I still have to learn a lot.


Well thanks for the replies :smiley: