@@ -12,6 +12,10 @@ discard block |
||
| 12 | 12 | throw new \RuntimeException($error['message']); |
| 13 | 13 | } |
| 14 | 14 | } |
| 15 | +/** |
|
| 16 | + * @param integer $status |
|
| 17 | + * @param string $message |
|
| 18 | + */ |
|
| 15 | 19 | function respond_rest($con, $status, $message, $content) { |
| 16 | 20 | try { |
| 17 | 21 | $length = strlen($content); |
@@ -24,6 +28,11 @@ discard block |
||
| 24 | 28 | } |
| 25 | 29 | fclose($con); |
| 26 | 30 | } |
| 31 | +/** |
|
| 32 | + * @param Closure $tick_function |
|
| 33 | + * @param integer $tick |
|
| 34 | + * @param integer $times |
|
| 35 | + */ |
|
| 27 | 36 | function respond_streaming($con, $tick_function, $tick, $times) { |
| 28 | 37 | try { |
| 29 | 38 | fsend($con, "HTTP/1.1 200 OK\r\n"); |
@@ -55,8 +55,9 @@ discard block |
||
| 55 | 55 | $con = @stream_socket_accept($socket, -1); |
| 56 | 56 | if (!$con) { |
| 57 | 57 | $err = error_get_last(); // どーなんだこれ strerror(EINTR) |
| 58 | - if (strpos($err["message"], "Interrupted system call") !== false) |
|
| 59 | - continue; |
|
| 58 | + if (strpos($err["message"], "Interrupted system call") !== false) { |
|
| 59 | + continue; |
|
| 60 | + } |
|
| 60 | 61 | fwrite(STDERR, "[Server] " . $err["message"] . "\n"); |
| 61 | 62 | exit(1); |
| 62 | 63 | } |
@@ -91,7 +92,9 @@ discard block |
||
| 91 | 92 | parse_str(isset($parsed['query']) ? $parsed['query'] : '', $q); |
| 92 | 93 | foreach ($endpoints as $endpoint => $action) { |
| 93 | 94 | if ($parsed['path'] === $endpoint || $endpoint === '') { |
| 94 | - if ($endpoint === '') $endpoint = '[Undefined]'; |
|
| 95 | + if ($endpoint === '') { |
|
| 96 | + $endpoint = '[Undefined]'; |
|
| 97 | + } |
|
| 95 | 98 | fwrite(STDERR, "Request: $parts[1]\n"); |
| 96 | 99 | $action($con, $q); |
| 97 | 100 | exit(0); |
@@ -323,8 +323,10 @@ |
||
| 323 | 323 | // NOTE: DO NOT call curl_multi_remove_handle |
| 324 | 324 | // or curl_multi_add_handle while looping curl_multi_info_read! |
| 325 | 325 | $entries = array(); |
| 326 | - do if ($entry = curl_multi_info_read($this->mh, $remains)) { |
|
| 326 | + do { |
|
| 327 | + if ($entry = curl_multi_info_read($this->mh, $remains)) { |
|
| 327 | 328 | $entries[] = $entry; |
| 329 | + } |
|
| 328 | 330 | } while ($remains); |
| 329 | 331 | // Remove done and consume queue. |
| 330 | 332 | foreach ($entries as $entry) { |