fix ::toStream() in ZTS
authorMichael Wallner <mike@php.net>
Mon, 16 Feb 2015 12:13:48 +0000 (13:13 +0100)
committerMichael Wallner <mike@php.net>
Mon, 16 Feb 2015 12:34:46 +0000 (13:34 +0100)
php_http_message.c
tests/helper/proxy.inc
tests/helper/server.inc

index efdf053c244fba3d413a1adee177eabca0929083..b7b500b313bbea8b1308c194e14e1e653cc0b33c 100644 (file)
@@ -1677,6 +1677,16 @@ static PHP_METHOD(HttpMessage, toString)
        RETURN_EMPTY_STRING();
 }
 
+#ifdef ZTS
+static size_t write_to_stream(void *s, const char *str, size_t len)
+{
+       TSRMLS_FETCH();
+       return php_stream_write(s, str, len);
+}
+#else
+#      define write_to_stream (php_http_pass_callback_t)_php_stream_write
+#endif
+
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toStream, 0, 0, 1)
        ZEND_ARG_INFO(0, stream)
 ZEND_END_ARG_INFO();
@@ -1691,7 +1701,7 @@ static PHP_METHOD(HttpMessage, toStream)
                PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                php_stream_from_zval(s, &zstream);
-               php_http_message_to_callback(obj->message, (php_http_pass_callback_t) _php_stream_write, s);
+               php_http_message_to_callback(obj->message, write_to_stream, s);
        }
 }
 
index 61b20dd1c1b38e3a26190d5d401216387991bc07..363d76f4b88be43a61ff0649caafa0c98d5e9a04 100644 (file)
@@ -16,6 +16,7 @@ serve(function($client) {
        
        /* return the initial message as response body */
        $response = new http\Env\Response;
-       $response->getBody()->append($request);
+       /* avoid OOM with $response->getBody()->append($request); */
+       $request->toStream($response->getBody()->getResource());
        $response->send($client);
 });
index 26f0c5041c0faff35b2aa512f360f97b673ba902..ed8516b3a6a6b07d0809a6328d30a504b0dda63e 100644 (file)
@@ -11,8 +11,13 @@ function serve(callable $cb) {
                                        if (getenv("PHP_HTTP_TEST_SSL")) {
                                                stream_socket_enable_crypto($client, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER);
                                        }
-                                       while (!feof($client)) {
-                                               $cb($client);
+                                       try {
+                                               while (!feof($client)) {
+                                                       $cb($client);
+                                               }
+                                       } catch (Exception $ex) {
+                                               fprintf(STDERR, "%s\n", $ex);
+                                               break;
                                        }
                                }
                        } while ($select !== false);