williamZanelli Posted February 15, 2011 Share Posted February 15, 2011 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. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 15, 2011 Share Posted February 15, 2011 what inefficiencies are you experiencing? heavy server load? out of memory errors? my opinion: if it ain't broke, don't fix it. Quote Link to comment Share on other sites More sharing options...
williamZanelli Posted February 15, 2011 Author Share Posted February 15, 2011 Well at the moment there's been no such issue with heavy load etc. However, given that I'm implementing code in this section, I'd much rather do the best way possibe - than to do a half ass job and then later realise its not as efficient/proper way of doing it. Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted February 15, 2011 Share Posted February 15, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.