Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make a PHP script run itself every hour or so without the use of a cronjob?

Tags:

php

cron

I'm pretty sure I've seen this done in a php script once, although I cant find the script. It was some script that would automatically check for updates to that script, and then replace itself if there was an update.

I don't actually need all that, I just want to be able to make my PHP script automatically run every 30 minutes to an hour, but I'd like to do it without cronjobs, if its possible.

Any suggestions? Or is it even possible?

EDIT: After reading through a possible duplicate that RC linked to, I'd like to clarify.

I'd like to do this completely without using resources outside of the PHP script. AKA no outside cronjobs that send a GET request. I'd also like to do it without keeping the script running constantly and sleeping for 30 minutes

like image 707
Rob Avatar asked May 16 '10 07:05

Rob


2 Answers

If you get enough hits this will work...

Store a last update time somewhere(file, db, etc...). In a file that gets enough hits add a code that checks if the last update time was more xx minutes ago. If it was then run the script.

like image 177
Galen Avatar answered Sep 18 '22 08:09

Galen


You may want to use the PHP's sleep function with specified time to run your code with that interval or you may want to try some online cron job services if you wish.

like image 40
Sarfraz Avatar answered Sep 18 '22 08:09

Sarfraz