NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Running script in background continously


Joined: 24 Oct 2006
Posts: 1
Location: Celje, Slovenia
Reply with quote
Hi,

how to run PHP script in the background which would execute main function(s) every 10 minutes? Consider checking what needs to do be done (from database, updating) and then script would transfer data from web and write it to SQLite database.

There's even one idea in web to have hidden IFRAME which would call PHP script (and this would have HTML meta tag to refresh every 10 minutes etc). Of course I'm looking for a PHPDock solution.

If this is solvable with PHPDock then all AT jobs, exec() spawning etc are things of the past (on Window$).

Thanks, Sergej

P.S: What about running PHPDock as a service (on startup) with hiding icon in system tray?
View user's profileFind all posts by SergioGuruSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Did you see jobs in the phpdock's ini?
They are run in background and therefore you may have something like this in a job handler:
<?
while (1) {
do_my_great_work();
sleep(60 * 10); // 10 min to sleep
}

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 23 Jan 2007
Posts: 6
Reply with quote
Is there any built-in way of treating the jobs like actual CRON jobs (i.e. being able to schedule when the job runs, independent of when PHP Dock was launched)? For instance, I have an app that needs to perform an import. The data to import will be ready at a specific time each day, and I want a job to kick off at that time.

Based on your example here, the only way I can think of to accomplish this would be to calculate the amount of time until the import on startup and sleep that amount of time, perform the import, then subsequently sleep for 24 hours before performing the import again (in case the user leaves PHP Dock open all night, which is common). I'm pretty sure this would work, I was just wondering if there was a more elegant solution via the INI file for scheduling a job.

Also, is there any way to get the settings in the phpdock.ini file from PHP code (maybe as server variables)? The reason I ask is that if I do have to schedule my jobs the way I described above, I would want to be able to specify the import time(s) in the INI file, as custom entries. Otherwise I suppose I could just open the INI file using PHP and read the entries directly, or put them in a separate INI file and read that.
View user's profileFind all posts by clarkke8Send private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
I think that in one of the next versions we will change the way phpdock works with settings. It will be possible to embed ini and lic files into exe and distribute only exe. So it's not that good to update phpdock.ini by applications. Better to use your own ini file.

Quote:
way I can think of to accomplish this would be to calculate the amount of time until the import on startup and sleep that amount of time

Almost correct, but you need to take into account that schedule may change while the thread is already sleeping. I think it's better not to sleep for longer than time granularity. If for example 10minutes precision is okay, split whole the amount of time into 10min chunks and make thread sleeping in the loop. Check for the timetable changes should be performed on each chunk (either before going sleep or right after).

Quote:
Is there any built-in way of treating the jobs like actual CRON jobs

fyi, there is a TimeSchedule thing in Windows:
http://msdn2.microsoft.com/en-us/library/aa383614(VS.85).aspx
all the API is available with command-line tool http://msdn2.microsoft.com/en-us/library/bb736357(VS.85).aspx

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Running script in background continously
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic