Jump to content

Recommended Posts

I've seen 'set_time_limit()' and 'max_execution_time' references in php manual. But they say that it doesnt include mysql queries. Being that this script is sql-query intensive, i would imagine i need an alternate solution to ensuring a script closes 'x' seconds from the moment the first line is executed/file is opened.

 

Any ideas?

 

(if you want to know why, i have a cron which will run a file (with infinite loop checking and altering Mysql) every 15 minutes, however i wish to ensure one cron never clashes with the next.)

(if you want to know why, i have a cron which will run a file (with infinite loop checking and altering Mysql) every 15 minutes, however i wish to ensure one cron never clashes with the next.)

When the cron runs, it tests for the existence of a lock file. If that lock file exists, it simply terminates (previous cron still running). If the file doesn't exist, it creates it. When it finishes running, it deletes the lock file.

 

I built a world map based on coordinates system. the crons updates everyones new co-ordinates.

 

that lock file is not true because i have 7 of these processes running right now (Just checked).

had it run every 15 minutes with a set_time_limit(900) at start script. i Know from experience that it wont ever allow more than 7 of the same process. or perhaps of any cron file.

 

 

I built a world map based on coordinates system. the crons updates everyones new co-ordinates.

No wonder it takes so long to run. GPS tracking for everyone in the world.... have you claimed the reward for Osama Bin Laden yet?

 

that lock file is not true because i have 7 of these processes running right now (Just checked).

The lock file method will work. If it's not working for your code, then your code isn't doing the checks correctly.

 

 

$processLockFileName = 'lockFile.lck';
if (file_exists($processLockFileName)) {
exit('Already running');
}
$processLockFile = fopen($processLockFileName,'w+');
flock($processLockFile,LOCK_EX);
...
...
...
flock($processLockFile,LOCK_UN);
fclose($processLockFile);
unlink($processLockFileName);

The alternative is to ensure your script exits after 14 minutes by doing comparisons based on the output of time() when the script started, and currently

 

$otime = time()

while ( true ){
    $scriptRunningTime = time() - $otime;
    if ( $scriptRunningTime > 60 * 14 ) break; //14 mins
}

 

It depends if what you are doing ever has an end. If it has an end, it would be better to use the lock method I would assume. More logical at least.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.