php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #26449 usleep doesnt work correctly
Submitted: 2003-11-28 10:54 UTC Modified: 2004-06-05 11:07 UTC
From: marcus at quintic dot co dot uk Assigned: wez (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.4 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marcus at quintic dot co dot uk
New email:
PHP Version: OS:

 

 [2003-11-28 10:54 UTC] marcus at quintic dot co dot uk
Description:
------------
(I know the manual says it doesnt work, but it should work because the Sleep function in windows works fine)

usleep doesnt work on windows XP (on all windows platforms?). For some reason usleep returns immediately on windows and there doesnt seem to be any way in php of delaying for less than a second without chewing cpu cycles.

Having looked at the code behind the usleep function all it does is call the win32 Sleep function which does work, so there must be a bug stopping this from being called.

Reproduce code:
---------------
<?php usleep(100000); ?>

Expected result:
----------------
Should delay for 100000 microseconds.

Actual result:
--------------
Returns immediately with no delay.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-28 11:17 UTC] iliaa@php.net
Try making the delay longer, usleep(100000); will sleep for 1/10 of a second and is very hard to notice.
 [2003-11-28 11:25 UTC] marcus at quintic dot co dot uk
Doesnt work. I only put 100000 as an example (admittedly too small to notice if you're watching it), I should have put 10000000 or something - put it in a loop that repeats a few thousand times and it still doesnt do anything.
 [2003-11-28 14:01 UTC] iliaa@php.net
Try running the following:
php -r " var_dump(time(), usleep(10000000), time()); "
 [2003-11-28 15:37 UTC] marcus at quintic dot co dot uk
Ok - I wont be able to check until after the weekend. I 
tried the output of  
 
<?php echo time(); usleep(10000000); echo time(); ?> 
 
earlier (before submitting the bug) and it comes back with 
the same time twice so unless var_dump gives you any extra 
info that will help....
 [2003-11-29 06:15 UTC] sniper@php.net
RTFM: Note:  This function does not work on Windows systems.
(Yes, manual might be correct?)

The function exists, but it does absolutely nothing on windows.

 [2003-11-29 15:57 UTC] marcus at quintic dot co dot uk
So every other language I know manages to call Sleep under  
win32 and it works, but php doesnt?
 [2003-11-29 16:08 UTC] wez@php.net
Sleep() has millisecond resolution, not microsecond resolution.

I'll look into getting usleep working under win32, but
make no promises.
 [2003-11-29 16:11 UTC] marcus at quintic dot co dot uk
:) Hell, who need microseconds anyway - being able to 
delay for less than a second without chewing cpu would be 
enough for me. Thanks.
 [2003-11-29 17:58 UTC] wez@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

I've implemented this in PHP 5.
Since it requires win98 and later, it might not go into the php4 branch.
Please try a php 5 snapshot and let us know how well it works for you.
 [2003-12-04 02:26 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2004-01-12 19:45 UTC] antispammail at gmx dot de
I also really NEEED this usleep function to work,
but tested the latest php 5 as advised an
it does not work :(

Have you removed this feature allready again? why?

according to this :
http://groups.google.com/groups?q=usleep+win32&hl=de&lr=&ie=UTF-8&oe=UTF-8&selm=9401pp%242fgt%241%40FreeBSD.csie.NCTU.edu.tw&rnum=3

===========================================================
[2001-01-15 18:22:56] christophe@winamp.com
usleep exists on Win32 as the Sleep command (it takes a millisecond value as parameter) so here is the patch for making the usleep() php function to work on win32 platforms:

in main/win95nt.h, line 27:

#define php_sleep(t) Sleep(t*1000)

add the following line so it looks like:
#define php_sleep(t) Sleep(t*1000)
#define usleep(t)  Sleep(t)

and in config.w32.h, line 93:

/* Define if you have the usleep function.  */
#undef HAVE_USLEEP

change it to:

/* Define if you have the usleep function.  */
#define HAVE_USLEEP 1

-Christophe Thibault
Nullsoft (www.nullsoft.com/www.winamp.com)
===========================================================

I just don't know how to do this change as a "user" of php ... PLEASE HELP and put this in the new release!

Chris
 [2004-01-12 21:05 UTC] wez@php.net
The next php5 snapshot should include a correctly working usleep().
 [2004-06-04 16:42 UTC] marcus at quintic dot co dot uk
Looks like it works with PHP5 RC2 thanks! How about a backport to v4? Thanks again
 [2004-06-05 11:07 UTC] derick@php.net
We do not make new features available in PHP 4 as it's in "bug fix only mode".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC