HuntsvilleMan Posted May 18, 2011 Share Posted May 18, 2011 Are there any practical limits to how long the sleep() function can be set to halt an application? I’m using Yahoo Small Business as for web hosting and would like to set some applications to sleep for as long as 12 hours. Is this likely to be a resource problem Yahoo will ding me for? Thanks Mike Quote Link to comment https://forums.phpfreaks.com/topic/236695-how-long-can-a-program-sleep/ Share on other sites More sharing options...
requinix Posted May 18, 2011 Share Posted May 18, 2011 There isn't much on their website as to what you can or cannot do technically. Mostly just legal butt-covering. They provide a toll-free number to call for help. I'd suggest you call and see what they say on the matter. Besides that, I wouldn't do it. Even on my own machines. Regardless of whether it can or can't, PHP wasn't designed to run for long periods. There are issues with memory leaks (the longer your script runs the more memory it sucks up on the machine) and garbage collection (might hold a claim to memory that it doesn't actually need anymore), for starters. The real question is what kinds of things you need to run - and not even that, just sit around idly - for hours and hours on end. So what's up with that? Quote Link to comment https://forums.phpfreaks.com/topic/236695-how-long-can-a-program-sleep/#findComment-1216756 Share on other sites More sharing options...
QuickOldCar Posted May 18, 2011 Share Posted May 18, 2011 If it's something that is to be done once or twice a day or any timed manner, then a cron job would be better. http://en.wikipedia.org/wiki/Cron If using cpanel http://www.upstartblogger.com/how-to-create-a-cron-job-in-cpanel or from command line using editor such as vim http://adminschoice.com/crontab-quick-reference Quote Link to comment https://forums.phpfreaks.com/topic/236695-how-long-can-a-program-sleep/#findComment-1216763 Share on other sites More sharing options...
HuntsvilleMan Posted May 20, 2011 Author Share Posted May 20, 2011 Sure appreciate the heads up about what to look for to schedule task. Looks like Yahoo Small Business does not offer cron or cpanel. They probably don't have anything else for task management that I can have access to. At least I haven't found anyone on their help line with answers. Guess I'll have to see if sleep() can be made to do what I need. The application I have in mind is one that fills the role of a traditional answering service for a doctor taking after hour calls that in essence tracks down the doc when needed by calling various phones and building a call logic that at intervals based on what is learned from people answering the phones and punching in what they know figures out the best way to find the person. Sometime the person being hunted can be at any one 5 or more locations, out of cell phone and beeper contant and maybe even dead asleep. Dozing off is common for emergency workers at 3am on slow mornings (think air trafic controllers at lonely airports). So it also becomes the alarm clock in some cases. Well, that's what docs pay answering services to do and seemed like it could be automated using some PHP and cute services at twilio.com. By the way, all that Yahoo Small Business offers by way of PHP functions is listed below. Array functions BCMath Arbitrary Precision Mathematics functions Calendar functions Character type functions Class/Object functions CURL, Client URL Library functions Database (dbm-style) abstraction layer functions Date and Time functions Directory functions DOM functions DOM XML functions Error Handling and Logging functions Exif functions Filesystem functions Function Handling functions HTTP functions iconv functions Image functions JSON functions Mail functions Mathematical functions Mcrypt Encryption functions Mhash functions Mimetype functions Ming functions for Flash Miscellaneous functions Multibyte String functions MySQL functions Network functions (fsockopen and pfsockopen are disabled) Object property and method call overloading OpenSSL functions Output Control functions PHP options & information Pspell functions Regular Expression functions (Perl-compatible) Regular Expression functions (POSIX Extended) Session handling functions Stream functions String functions Tokenizer functions URL functions Variable handling functions WDDX functions XML parser functions XML-RPC functions XSLT functions Zip File functions (read-only access) Zlib Compression functions Quote Link to comment https://forums.phpfreaks.com/topic/236695-how-long-can-a-program-sleep/#findComment-1217868 Share on other sites More sharing options...
QuickOldCar Posted May 20, 2011 Share Posted May 20, 2011 Then another suggestion would be to make a script that cycles each of your customers in loops, and do a select to mysql or even sqlite going by date, basically a "last time date checked". If last date checked less than 12 hours, run another script to do any actions. At the same time update the last date checked to the current time. sleep() is not good to do unless for a very small amount and only when absolutely necessary. Quote Link to comment https://forums.phpfreaks.com/topic/236695-how-long-can-a-program-sleep/#findComment-1217872 Share on other sites More sharing options...
btherl Posted May 20, 2011 Share Posted May 20, 2011 I would expect Yahoo to cruelly kill your processes in their sleep. But it doesn't hurt to try. One option, assuming you have a pc on 24/7 and a reliable internet connection, is to run something on your pc that regularly hits a url on your webserver. Or you can run a cron job on a hosting service that DOES allow cron jobs, and have it poll your Yahoo site. That's a bit roundabout but it can work. QuickOldCar's idea is good - the database can remember what's been done already, and your script's strategy can be "Check what needs doing in the database, do it, then update the database and exit". Quote Link to comment https://forums.phpfreaks.com/topic/236695-how-long-can-a-program-sleep/#findComment-1217879 Share on other sites More sharing options...
RussellReal Posted May 20, 2011 Share Posted May 20, 2011 what you should do, buy a cheap $2 webhosting that supports cron, run the cron job for every 2 seconds or 3 seconds the php file would simply be to check if there are any queued calls... then dispatch them, then wait to be activated again.. whichever company you work for wouldn't have a problem with paying the extra $24/year for this to work out.. thats the easiest sollution, aswell as most practical. however, if you want to use sleep(), for over 12 hours, you're most likely gonna want to double check with Yahoo! Small Business if its okay Quote Link to comment https://forums.phpfreaks.com/topic/236695-how-long-can-a-program-sleep/#findComment-1217883 Share on other sites More sharing options...
kenrbnsn Posted May 20, 2011 Share Posted May 20, 2011 run the cron job for every 2 seconds or 3 seconds The minimum interval for a cronjob is 1 minute. Ken Quote Link to comment https://forums.phpfreaks.com/topic/236695-how-long-can-a-program-sleep/#findComment-1217892 Share on other sites More sharing options...
HuntsvilleMan Posted May 21, 2011 Author Share Posted May 21, 2011 Sounds like the best suggestion is to find a more accomodating web hosting service. Till recently all I wrote were desktop applications and now it seem I'm finding more interesting uses for web applications almost every day. Guess I need a web hosting service that gives me more opportunity to explore and try new things. Anyone have experience with a web hosting service that meets that goal? Thanks Mike Quote Link to comment https://forums.phpfreaks.com/topic/236695-how-long-can-a-program-sleep/#findComment-1218302 Share on other sites More sharing options...
RussellReal Posted May 24, 2011 Share Posted May 24, 2011 run the cron job for every 2 seconds or 3 seconds The minimum interval for a cronjob is 1 minute. Ken yes, I know, but that means 1 script is being ran every (24*60*60) times per day, to do something that doesn't need to be completely automatic 3 seconds is perfectly fine I thought, but you could run it every 1 second for sure.. Quote Link to comment https://forums.phpfreaks.com/topic/236695-how-long-can-a-program-sleep/#findComment-1219557 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.