Page 1 of 1
Using sleep() for delayed output effects
Posted: Tue Sep 22, 2009 10:18 am
by kendall
Hey guys,
I need some advice I am trying to develop a service which tranfers files from one place to the next for converting. I developed a progress display sequence in PHP which uses sleep() and flush() loop to run a progress bar update for the transfer. Now the thing is that some of these files maybe large ( <= 10M).
is this a good/ effective or efficeint implementation to use?
Any suggestions pros or cons on this?
Kendall
Re: Using sleep() for delayed output effects
Posted: Tue Sep 22, 2009 10:51 am
by Jenk
Only one that springs to mind is the possibility that your sleep() may cause the user agent to assume the connection has been lost (if long enough of a delay.)
Perhaps an asynchronous poll would be better than using sleep()/flush() though. Using sleep() just feels dirty to me.

Re: Using sleep() for delayed output effects
Posted: Tue Sep 22, 2009 11:07 am
by kendall
Jenks,
coool. I am using it with an asynchronous upload function one thing im noticing that my server seems to "slow down". Well i'm using it on local server and this is not something I would use to benchmark anything.

Re: Using sleep() for delayed output effects
Posted: Tue Sep 22, 2009 11:32 am
by kendall
I notice that with the script on sleep() I apparently can't use it until its finished. the sleep is actually from an included file. Is there a way around this?
Re: Using sleep() for delayed output effects
Posted: Tue Sep 22, 2009 3:42 pm
by josh
There's jquery plugins that do a lot of stuff like display ETA and such and have smoother animation, would not try to achieve "delayed output effects" in PHP, its a "smell" ( less then optimal design ).
For ex. when uploading videos to youtube it goes into a "processing" state, it could either poll via ajax or the user could just check back in several minutes to view the updated status ( the task should happen in the background, not in a process the user can stop halfway thru )
Re: Using sleep() for delayed output effects
Posted: Tue Sep 22, 2009 3:50 pm
by kendall
I am thinking that it maybe best. I was really trying to avoid any sort of non-php option to keep a consitency avoiding having to re-invent what I already had just to accomodate having to use JS library to achieve this process....alast i guess i have no choice...
Thanks
Re: Using sleep() for delayed output effects
Posted: Mon Sep 28, 2009 10:09 pm
by Selkirk
Holding the connection open will hurt your server capacity. You can use a library with a bit of flash to do this. LIke
YUI Uploader.
Re: Using sleep() for delayed output effects
Posted: Tue Sep 29, 2009 6:30 am
by kendall
I am realizing this....I went ahead and installed the uploadprogress PECL extension. I have decided to $_POST instead of FTP...don't know how efficient is this