Jump to content

PHP CLI vs WGET in Cron


williamZanelli

Recommended Posts

Hi guys,

 

Periodically I have a need to execute some local PHP file to clean/update the DB - it takes some parameters.

 

So I use a Cron file, that has WGET statments passing arguments in the URL.

 

The benefit of this is to me is, I can manually via the browser execute the same file.

 

I have been told that using PHP CLI is more efficient,

 

Can anyone shed any light on this? Is it more efficient? Would i be able to manually excecute the PHP CLI file via a browser?

 

Thanks for your thoughts in advance.

 

 

 

 

Link to comment
Share on other sites

Simple answer. Any process that requires no output to screen and can be run on a schedule should be implemented as a command line script, whether it be in PHP, Perl, or whatever.

The script should not even be accessible through a web browser, i.e stored outside of the web document root.

 

So I use a Cron file, that has WGET statments passing arguments in the URL

Bad. You can still pass arguments into command line scripts. This sort of script should not even be accessible via a URL. WGET is not really used for what you are using it for. Your cron should use the path to the script, not a URL.

 

I have been told that using PHP CLI is more efficient

For the sort of task that you require such as a maintenence operation, yes. As you are not using a web browser to request the script there is no overhead from the Apache web server. Nor are there any restrictions in place such as timeouts.

 

Would i be able to manually excecute the PHP CLI file via a browser?

Yes you can. If required you can fork a script to process in the background using php's exec() function. For instance I may want to send a newsletter out to lots of members when I click a button on my website. I am not going to sit there and wait for this to complete in my web browser, instead the script is run as a background process through the command line. i.e

exec("php /path/to/script.php > /dev/null &");

Be aware that shared hosts do not normally allow the use of exec() for security reasons.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.