]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #47893 (CLI aborts on non blocking stdout)
authorArnaud Le Blanc <lbarnaud@php.net>
Tue, 7 Apr 2009 16:11:57 +0000 (16:11 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Tue, 7 Apr 2009 16:11:57 +0000 (16:11 +0000)
NEWS
sapi/cli/php_cli.c

diff --git a/NEWS b/NEWS
index 2e973241356e1c4d1032f40d345eb8a1102d0f14..2e84e299f81d95d8e9680446bef1d6addf73b1dc 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ PHP                                                                        NEWS
 - Fixed segfault on invalid session.save_path. (Hannes)
 
 - Fixed bug #47903 ("@" operator does not work with string offsets). (Felipe)
+- Fixed bug #47893 (CLI aborts on non blocking stdout). (Arnaud)
 - Fixed bug #47849 (Non-deep import loses the namespace). (Rob)
 - Fixed bug #47845 (PDO_Firebird omits first row from query). (Lars W)
 - Fixed bug #47831 (Compile warning for strnlen() in main/spprintf.c).
index 1d9516cc8df2366d12ed1ba8584a9c751462fdfc..22c2fd28ed4ea65224c2a7e7969959c0adde910d 100644 (file)
 
 #include "php_getopt.h"
 
+#ifndef PHP_WIN32
+# define php_select(m, r, w, e, t)     select(m, r, w, e, t)
+#else
+# include "win32/select.h"
+#endif
+
 PHPAPI extern char *php_ini_opened_path;
 PHPAPI extern char *php_ini_scanned_files;
 
@@ -224,15 +230,38 @@ static void print_extensions(TSRMLS_D) /* {{{ */
 #define STDOUT_FILENO 1
 #endif
 
+static inline int sapi_cli_select(int fd)
+{
+       fd_set wfd, dfd;
+       struct timeval tv;
+       int ret;
+
+       FD_ZERO(&wfd);
+       FD_ZERO(&dfd);
+
+       PHP_SAFE_FD_SET(fd, &wfd);
+
+       tv.tv_sec = FG(default_socket_timeout);
+       tv.tv_usec = 0;
+
+       ret = php_select(fd+1, &dfd, &wfd, &dfd, &tv);
+
+       return ret != -1;
+}
+
 static inline size_t sapi_cli_single_write(const char *str, uint str_length) /* {{{ */
 {
 #ifdef PHP_WRITE_STDOUT
        long ret;
 
-       ret = write(STDOUT_FILENO, str, str_length);
+       do {
+               ret = write(STDOUT_FILENO, str, str_length);
+       } while (ret <= 0 && errno == EAGAIN && sapi_cli_select(STDOUT_FILENO));
+
        if (ret <= 0) {
                return 0;
        }
+
        return ret;
 #else
        size_t ret;