amalesev Posted April 2, 2012 Share Posted April 2, 2012 I am trying to write a script that is going to access a database, grab the newest picture from it, find the height and width, analyze the height and width to find which command (which is assigned to a variable) is the one to run, run that command in the terminal, and then access the database again 6 seconds later (new pictures are uploaded every 6 seconds) and re-run and enter the command for this new picture. I have most of this already done, the problem I am having is figuring out how to get this to run every 6 seconds for forever. (Yes it has to be every 6 seconds.) Can anyone help me? Thanks in advance for the help! Quote Link to comment https://forums.phpfreaks.com/topic/260192-run-every-6-seconds/ Share on other sites More sharing options...
rythemton Posted April 2, 2012 Share Posted April 2, 2012 Try using Cron jobs, or some other scheduler. This should work even if your hosting doesn't allow scripts to run continuously, which some do restrict. Quote Link to comment https://forums.phpfreaks.com/topic/260192-run-every-6-seconds/#findComment-1333578 Share on other sites More sharing options...
ocpaul20 Posted April 2, 2012 Share Posted April 2, 2012 cron does not go down to that low a time period, does it? I think you need to redesign the system if it has to be run every 6 seconds. Are you sure there is no other way? This is virtually continuously so maybe you write a service which looks for a file in a directory, once it finds it, it processes it and returns to looking for the next one after delay 1 second?. That way, whenever the file appears, it will be processed. off the top of my head... while (1 = 1) { clearstatcache(); while( !file_exists(xxx)) { sleep for 1 second } // do processing } // while 1 = 1 dont know if this would work, but you would have to test it. Quote Link to comment https://forums.phpfreaks.com/topic/260192-run-every-6-seconds/#findComment-1333581 Share on other sites More sharing options...
batwimp Posted April 2, 2012 Share Posted April 2, 2012 You can input 10 cron jobs and delay them in increments of six seconds. http://aragorndhk.blogspot.com/2009/04/run-cron-job-in-seconds.html Quote Link to comment https://forums.phpfreaks.com/topic/260192-run-every-6-seconds/#findComment-1333583 Share on other sites More sharing options...
rythemton Posted April 2, 2012 Share Posted April 2, 2012 Are you sure there is no other way? There is almost always more than one way to perform a task. The reason I suggested Cron Jobs is because the use the clock, rather than a timer, to determine when to run a task, allowing for greater consistency. If you have access enough to the server to allow for scripts to run forever, you could also use the time() function to determine when to act. $checktime = time(); while( TRUE ) { if( time() > $checktime ) { $checktime += 6; // perform actions } } Quote Link to comment https://forums.phpfreaks.com/topic/260192-run-every-6-seconds/#findComment-1333626 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.