php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29474 Function usleep doesn't work under Windows.
Submitted: 2004-07-31 22:40 UTC Modified: 2004-08-01 02:39 UTC
From: cucup at bol dot com dot br Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 5.0.0 OS: Windows 98
Private report: No CVE-ID: None
 [2004-07-31 22:40 UTC] cucup at bol dot com dot br
Description:
------------
Function usleep doesn't work under Windows.

I know this is documented, but I believe PHP5 could have this function working fine... Why not?

Function "sleep" isn't enough for a lot of projects.

There's a bug report in version 4.xx, in wich "dror at europe dot com" reported a solution for the source code.. It could be easily implemented in official PHP5 Source.

PHP_FUNCTION(usleep)
{
	pval **num;

	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE)
{
		WRONG_PARAM_COUNT;
	}
	convert_to_long_ex(num);

#### Begin modifications from original source
#if HAVE_USLEEP
	usleep((*num)->value.lval);
#elif PHP_WIN32
   Sleep( ((*num)->value.lval+999)/1000);
#endif
#### End modifications
}


Reproduce code:
---------------
echo "Sleeping half second:";
usleep(500); // doesn't work under windows.. :(

Expected result:
----------------
Stop script execution for 1/2 second, or 500ms

Actual result:
--------------
Nothing happens, line is ignored.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-01 02:36 UTC] wez@php.net
Fixed this properly in CVS; the next batch of snapshots at http://snaps.php.net will contain the fix.

FYI: Sleep() with fractional arguments is not real usleep(), take a look at win32/time.c for a working implementation.
 [2004-08-01 02:39 UTC] wez@php.net
BTW: the u in usleep comes from "mu", the greek symbol used to denote microseconds, not milliseconds. usleep(500) is much shorter than 1/2 second.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 03:01:29 2024 UTC