justinl
justinl

Reputation: 10528

Why use sleep(1) in php?

I've seen in php code snippets that programmers sometimes use sleep(1). In particular I'm looking at an image library that does image processing, and right after the image processing part of the code they'll put sleep(1).

Is this just because they want to give the server a second to process the image before it continues executing the code? If I didn't have the sleep(1) in there would it really matter?

EDIT:
here is some sample code

$ToBMP = new ToBmp(); 

//======= convert jpg to bmp 
$ToBMP->image_info('myjpg.jpg'); 
$ToBMP->new_width  = 100; 
$ToBMP->new_height = 100; 
$ToBMP->imagebmp(time().".bmp"); 
sleep(1); 

//======== conevrt gif to bmp 
$ToBMP->image_info('myjpg.gif'); 
$ToBMP->new_width  = 200; 
$ToBMP->new_height = 200; 
$ToBMP->imagebmp(time().".bmp"); 
sleep(1); 

Upvotes: 0

Views: 2030

Answers (2)

Jon
Jon

Reputation: 437326

There's no reason to sleep after doing image processing. Maybe there's some filesystem operations in the code block?

In any case, we 'd have to see the exact code to answer definitely.

Update

Well, in this particular case, to make sure that the saved images have different files names :)

Upvotes: 3

Core Xii
Core Xii

Reputation: 6441

In this case I'd wager it's because the files are saved as time().".bmp"; If the script didn't sleep(1) after the first save, the second image would have the same file name, overwriting the first.

Upvotes: 7

Related Questions