Jump to content

PHP for periodic tasks - impossible


midnite

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

Link to comment
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 comment
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 comment
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 comment
Share on other sites

Java itself has task scheduler and it supports threads. I am more familiar with PHP and feel that PHP is stronger in manipulating HTML documents too.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...