iliaa           Sun Apr 10 12:25:11 2005 EDT

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/standard       basic_functions.c basic_functions.h 
  Log:
  Added time_sleep_until() function, which is a high precision mechanism of
  making a script sleep until specified timestamp.
  
  
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1867&r2=1.1868&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1867 php-src/NEWS:1.1868
--- php-src/NEWS:1.1867 Wed Apr  6 12:07:24 2005
+++ php-src/NEWS        Sun Apr 10 12:25:11 2005
@@ -83,6 +83,7 @@
   . fputcsv() (David Sklar)
   . posix_access() (Magnus)
   . htmlspecialchars_decode() (Ilia)
+  . time_sleep_until() (Ilia)
 - Added DomDocument::$recover property for parsing not well-formed
   XML Documents. (Christian)   
 - Added Cursor support for MySQL 5.0.x in mysqli (Georg)
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.708&r2=1.709&ty=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.708 
php-src/ext/standard/basic_functions.c:1.709
--- php-src/ext/standard/basic_functions.c:1.708        Wed Apr  6 10:19:14 2005
+++ php-src/ext/standard/basic_functions.c      Sun Apr 10 12:25:11 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.708 2005/04/06 14:19:14 iliaa Exp $ */
+/* $Id: basic_functions.c,v 1.709 2005/04/10 16:25:11 iliaa Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -167,6 +167,7 @@
        PHP_FE(usleep,                                                          
                                                        NULL)
 #if HAVE_NANOSLEEP
        PHP_FE(time_nanosleep,                                                  
                                                        NULL)
+       PHP_FE(time_sleep_until,                                                
                                                                NULL)
 #endif
        PHP_FE(time,                                                            
                                                        NULL)
        PHP_FE(mktime,                                                          
                                                        NULL)
@@ -1790,6 +1791,48 @@
        RETURN_FALSE;
 }
 /* }}} */
+
+/* {{{ proto mixed time_sleep_until(float timestamp)
+   Make the script sleep until the specified time */
+PHP_FUNCTION(time_sleep_until)
+{
+       double d_ts, c_ts;
+       struct timeval tm;
+       struct timespec php_req, php_rem;
+       
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &d_ts)) {
+               WRONG_PARAM_COUNT;
+       }
+
+       if (gettimeofday((struct timeval *) &tm, NULL) != 0) {
+               RETURN_FALSE;
+       }
+
+       c_ts = (double)(d_ts - tm.tv_sec - tm.tv_usec / 1000000.00);
+       if (c_ts < 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sleep until to 
time is less then current time.");
+               RETURN_FALSE;
+       }
+
+       php_req.tv_sec = (time_t) c_ts;
+       if (php_req.tv_sec > c_ts) { /* rounding up occurred */
+               php_req.tv_sec--;
+       }
+       /* 1sec = 1000000000 nanoseconds */
+       php_req.tv_nsec = (long) ((c_ts - php_req.tv_sec) * 1000000000.00);
+
+       while (nanosleep(&php_req, &php_rem)) {
+               if (errno == EINTR) {
+                       php_req.tv_sec = php_rem.tv_sec;
+                       php_req.tv_nsec = php_rem.tv_nsec;
+               } else {
+                       RETURN_FALSE;
+               }
+       }
+
+       RETURN_TRUE;
+}
+/* }}} */
 #endif
 
 /* {{{ proto string get_current_user(void)
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.h?r1=1.136&r2=1.137&ty=u
Index: php-src/ext/standard/basic_functions.h
diff -u php-src/ext/standard/basic_functions.h:1.136 
php-src/ext/standard/basic_functions.h:1.137
--- php-src/ext/standard/basic_functions.h:1.136        Wed Apr  6 10:19:14 2005
+++ php-src/ext/standard/basic_functions.h      Sun Apr 10 12:25:11 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: basic_functions.h,v 1.136 2005/04/06 14:19:14 iliaa Exp $ */
+/* $Id: basic_functions.h,v 1.137 2005/04/10 16:25:11 iliaa Exp $ */
 
 #ifndef BASIC_FUNCTIONS_H
 #define BASIC_FUNCTIONS_H
@@ -50,6 +50,7 @@
 PHP_FUNCTION(usleep);
 #if HAVE_NANOSLEEP
 PHP_FUNCTION(time_nanosleep);
+PHP_FUNCTION(time_sleep_until);
 #endif
 PHP_FUNCTION(flush);
 #ifdef HAVE_INET_NTOP

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to