Niccaman Posted March 31, 2009 Share Posted March 31, 2009 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.) Quote Link to comment https://forums.phpfreaks.com/topic/151871-solved-setting-a-max-execution-time-for-a-script/ Share on other sites More sharing options...
Philip Posted March 31, 2009 Share Posted March 31, 2009 That sounds like its pretty server intensive. May I ask why you want to do that? Quote Link to comment https://forums.phpfreaks.com/topic/151871-solved-setting-a-max-execution-time-for-a-script/#findComment-797517 Share on other sites More sharing options...
Mark Baker Posted March 31, 2009 Share Posted March 31, 2009 (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. Quote Link to comment https://forums.phpfreaks.com/topic/151871-solved-setting-a-max-execution-time-for-a-script/#findComment-797595 Share on other sites More sharing options...
Niccaman Posted April 1, 2009 Author Share Posted April 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/151871-solved-setting-a-max-execution-time-for-a-script/#findComment-798243 Share on other sites More sharing options...
Mark Baker Posted April 1, 2009 Share Posted April 1, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/151871-solved-setting-a-max-execution-time-for-a-script/#findComment-798425 Share on other sites More sharing options...
Yacoby Posted April 1, 2009 Share Posted April 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/151871-solved-setting-a-max-execution-time-for-a-script/#findComment-798472 Share on other sites More sharing options...
Niccaman Posted April 1, 2009 Author Share Posted April 1, 2009 Ty. The setting a time() + 60*14 idea was brilliant. Works as i need. Ty everyone for posting. Quote Link to comment https://forums.phpfreaks.com/topic/151871-solved-setting-a-max-execution-time-for-a-script/#findComment-798623 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.