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 efdf053..b7b500b 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 61b20dd..363d76f 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 26f0c50..ed8516b 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);