Jump to content

PHP for periodic tasks - impossible


Recommended Posts

Hi there,Is there any way that PHP alone can perform periodic tasks?There are a few solutions, with the help of the third parties:1) using JavaScript setTimeout() or setInterval() on a webpage to periodically request the PHP script. But we have to keep the web browser open. If the browser is closed, everything stops.2) using the OS scheduler, or another language to periodically call that PHP script. This will make the program become less portable. And also, if using another language to call the PHP, why not having the application written in that language.JS runs on web browser. PHP runs on web server. But PHP relies on browser calls to be triggered. My question seems like asking if PHP can escape from browser calls, run on its own on the web server. It is still alright if the PHP script has to be triggered by a browser call. But is it possible to keep the PHP script running after just one browser call (and close the browser)?Thank you very much,midnite

Edited by midnite
Link to post
Share on other sites

It is very common to use the Unix task scheduler (cron) to schedule PHP scripts to run. PHP is non-threaded and has an inbuilt timeout, and so is not suitable for running ongoing tasks. Remember that the PHP interpreter relies on the underlying platform to get itself run anyway, its sole job being to take a script, written in PHP, and interpret it. I mean, it can't even serve web pages by itself!You can run PHP scripts on the server arbitrarily from the terminal.

Link to post
Share on other sites

Hi Synook,Thanks very much for the reply and thanks for reminding me that PHP has an inbuilt timeout. So it is almost impossible to have periodic task on its own. Using cron on Linux is a good idea. A bit off topic. In your opinion, is it that Java seems to be the best choice, compared to C and PHP, if I has to access HTML, analyse DOM, and do it periodically? But outputting webpages from Java is definitely not as handy as PHP does.Best Regards,midnite

Link to post
Share on other sites

I don't really see much difference - PHP has more HTML-related functions and libraries though. What were you looking for in Java?

Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...