Skip to content

Instantly share code, notes, and snippets.

/php-fpm-stdin.patch Secret

Created Oct 18, 2016
Embed
What would you like to do?
patch for php-fpm bug
diff --git a/main/fastcgi.c b/main/fastcgi.c
index d2e1225..ed1974a 100644
--- a/main/fastcgi.c
+++ b/main/fastcgi.c
@@ -1398,6 +1398,7 @@ int fcgi_accept_request(fcgi_request *req)
req->hook.on_accept();
FCGI_LOCK(req->listen_socket);
+ fcntl(listen_socket, F_SETFL, O_RDWR);
req->fd = accept(listen_socket, (struct sockaddr *)&sa, &len);
FCGI_UNLOCK(req->listen_socket);
diff --git a/sapi/fpm/tests/023-stdin.phpt b/sapi/fpm/tests/023-stdin.phpt
new file mode 100644
index 0000000..79b020f
--- /dev/null
+++ b/sapi/fpm/tests/023-stdin.phpt
@@ -0,0 +1,56 @@
+--TEST--
+FPM: Test changing STDIN to non-blocking
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--FILE--
+<?php
+
+include "include.inc";
+
+$logfile = __DIR__.'/php-fpm.log.tmp';
+$srcfile = __DIR__.'/php-fpm.tmp.php';
+$port = 9000+PHP_INT_SIZE;
+
+$cfg = <<<EOT
+[global]
+error_log = $logfile
+[unconfined]
+listen = 127.0.0.1:$port
+pm = dynamic
+pm.max_children = 5
+pm.start_servers = 1
+pm.min_spare_servers = 1
+pm.max_spare_servers = 3
+EOT;
+
+$code = <<<EOT
+<?php
+stream_set_blocking(fopen('php://stdin', 'r'), false);
+EOT;
+file_put_contents($srcfile, $code);
+
+$fpm = run_fpm($cfg, $tail);
+if (is_resource($fpm)) {
+ fpm_display_log($tail, 2);
+ $req = run_request('127.0.0.1', $port, $srcfile);
+ proc_terminate($fpm);
+ echo stream_get_contents($tail);
+ fclose($tail);
+ proc_close($fpm);
+}
+
+?>
+Done
+--EXPECTF--
+[%s] NOTICE: fpm is running, pid %d
+[%s] NOTICE: ready to handle connections
+[%s] NOTICE: Terminating ...
+[%s] NOTICE: exiting, bye-bye!
+Done
+--CLEAN--
+<?php
+ $logfile = __DIR__.'/php-fpm.log.tmp';
+ $srcfile = __DIR__.'/php-fpm.tmp.php';
+ @unlink($logfile);
+ @unlink($srcfile);
+?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment