Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21695 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59166 invoked by uid 1010); 27 Jan 2006 01:07:22 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 59151 invoked from network); 27 Jan 2006 01:07:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jan 2006 01:07:22 -0000 X-Host-Fingerprint: 207.142.136.129 mail.kwikin.com Linux 2.4/2.6 Received: from ([207.142.136.129:37631] helo=mail.kwikin.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 11/D4-03249-94279D34 for ; Thu, 26 Jan 2006 20:07:22 -0500 Received: (qmail 11456 invoked from network); 27 Jan 2006 01:07:17 -0000 Received: from unknown (HELO madal.kwikin.com) (203.20.132.4) by mail.kwikin.com with SMTP; 27 Jan 2006 01:07:17 -0000 Date: Fri, 27 Jan 2006 11:07:15 +1000 X-Mailer: The Bat! (v2.12.00) Personal Reply-To: Tom Rogers Organization: Perfect Web Site Designs X-Priority: 3 (Normal) Message-ID: <1625742483.20060127110715@kwikin.com> To: internals@lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: usleep() on win32 From: trogers@kwikin.com (Tom Rogers) Hi Here is a small change to usleep so it will work with win32. It is very useful for tight while loops when using socket functions and reduces cpu load from 100% to 0%-2% (on my win2k box) by just adding usleep(1000); after the while(). (Code snippet was taken from pgsql) Diff is from php-4.4 cvs RCS file: /repository/php-src/ext/standard/basic_functions.c,v retrieving revision 1.543.2.51.2.6 diff -u -w -b -r1.543.2.51.2.6 basic_functions.c --- basic_functions.c 1 Jan 2006 13:46:57 -0000 1.543.2.51.2.6 +++ basic_functions.c 27 Jan 2006 00:52:10 -0000 @@ -1677,14 +1677,20 @@ Delay for a given number of micro seconds */ PHP_FUNCTION(usleep) { -#if HAVE_USLEEP pval **num; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long_ex(num); +#if HAVE_USLEEP usleep(Z_LVAL_PP(num)); +#else +#ifdef PHP_WIN32 + do { + SleepEx((Z_LVAL_PP(num) < 500 ? 1 : (Z_LVAL_PP(num) + 500) / 1000), TRUE); + } while(0); +#endif #endif } /* }}} */ -- Tom