Using sleep() for delayed output effects

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Using sleep() for delayed output effects

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Using sleep() for delayed output effects

Post 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. :)
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Re: Using sleep() for delayed output effects

Post 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. :lol:
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Re: Using sleep() for delayed output effects

Post 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?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Using sleep() for delayed output effects

Post 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 )
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Re: Using sleep() for delayed output effects

Post 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
Selkirk
Forum Commoner
Posts: 41
Joined: Sat Aug 23, 2003 10:55 am
Location: Michigan

Re: Using sleep() for delayed output effects

Post 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.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Re: Using sleep() for delayed output effects

Post 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
Post Reply