@@ -3,7 +3,6 @@ |
||
| 3 | 3 | require __DIR__ . '/../vendor/autoload.php'; |
| 4 | 4 | |
| 5 | 5 | use mpyw\Co\Co; |
| 6 | -use mpyw\Co\CURLException; |
|
| 7 | 6 | |
| 8 | 7 | function curl_init_with($url, array $options = [CURLOPT_RETURNTRANSFER => true]) { |
| 9 | 8 | $ch = curl_init($url); |
@@ -18,10 +18,10 @@ |
||
| 18 | 18 | |
| 19 | 19 | var_dump(Co::wait([ |
| 20 | 20 | "google.com HTML" => curl_init_with("https://google.com"), |
| 21 | - "Content-Length of github.com" => function () { |
|
| 21 | + "Content-Length of github.com" => function() { |
|
| 22 | 22 | return strlen(yield curl_init_with("https://github.com")); |
| 23 | 23 | }, |
| 24 | - "Save mpyw's Gravatar Image URL to local" => function () { |
|
| 24 | + "Save mpyw's Gravatar Image URL to local" => function() { |
|
| 25 | 25 | yield curl_init_with( |
| 26 | 26 | (yield get_xpath_async('https://github.com/mpyw')) |
| 27 | 27 | ->evaluate('string(//img[contains(@class,"avatar")]/@src)'), |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | $ch = curl_init(); |
| 20 | 20 | curl_setopt_array($ch, array( |
| 21 | 21 | CURLOPT_URL => "http://localhost:8080$path?" . http_build_query($q, '', '&'), |
| 22 | - CURLOPT_WRITEFUNCTION => function ($ch, $buf) use ($callback) { |
|
| 22 | + CURLOPT_WRITEFUNCTION => function($ch, $buf) use ($callback) { |
|
| 23 | 23 | $callback($buf); |
| 24 | 24 | return strlen($buf); |
| 25 | 25 | }, |
@@ -68,21 +68,21 @@ |
||
| 68 | 68 | continue; |
| 69 | 69 | } |
| 70 | 70 | $endpoints = array( |
| 71 | - '/rest' => function ($con, $q) { |
|
| 71 | + '/rest' => function($con, $q) { |
|
| 72 | 72 | $sleep = isset($q['sleep']) ? (int)$q['sleep'] : 0; |
| 73 | 73 | sleep($sleep); |
| 74 | 74 | $id = isset($q['id']) ? (int)$q['id'] : '?'; |
| 75 | 75 | respond_rest($con, 200, 'OK', "Rest response #$id (sleep: $sleep sec)\n"); |
| 76 | 76 | }, |
| 77 | - '/streaming' => function ($con, $q) { |
|
| 77 | + '/streaming' => function($con, $q) { |
|
| 78 | 78 | $tick = isset($q['tick']) ? (int)$q['tick'] : 1; |
| 79 | 79 | $id = isset($q['id']) ? (int)$q['id'] : '?'; |
| 80 | 80 | $times = isset($q['times']) ? (int)$q['times'] : 10; |
| 81 | - respond_streaming($con, function ($i) use ($id, $times) { |
|
| 81 | + respond_streaming($con, function($i) use ($id, $times) { |
|
| 82 | 82 | return "Rest response #$id ($i / $times, tick: $tick sec)\n"; |
| 83 | 83 | }, $tick, $times); |
| 84 | 84 | }, |
| 85 | - '' => function ($con, $q) { |
|
| 85 | + '' => function($con, $q) { |
|
| 86 | 86 | respond_rest($con, 404, 'Not Found', "Undefined path\n"); |
| 87 | 87 | }, |
| 88 | 88 | ); |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | // Wait 7 sec |
| 9 | 9 | print_time(); |
| 10 | -$result = Co::wait([curl('/rest', ['id' => 1, 'sleep' => 7]), function () { |
|
| 10 | +$result = Co::wait([curl('/rest', ['id' => 1, 'sleep' => 7]), function() { |
|
| 11 | 11 | // Wait 4 sec |
| 12 | 12 | print_r(yield [ |
| 13 | 13 | curl('/rest', ['id' => 2, 'sleep' => 3]), |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | print_time(); |
| 17 | 17 | // Wait 2 sec |
| 18 | 18 | print_r(yield [ |
| 19 | - function () { |
|
| 19 | + function() { |
|
| 20 | 20 | // Wait 1 sec |
| 21 | 21 | echo yield curl('/rest', ['id' => 4, 'sleep' => 1]), "\n"; |
| 22 | 22 | print_time(); |
| 23 | 23 | return curl('/rest', ['id' => 5, 'sleep' => 1]); |
| 24 | 24 | }, |
| 25 | - function () { |
|
| 25 | + function() { |
|
| 26 | 26 | // Wait 0 sec |
| 27 | 27 | echo (yield CO::SAFE => curl_init('invaild'))->getMessage(), "\n"; |
| 28 | 28 | print_time(); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | echo $e->getMessage(), "\n"; |
| 34 | 34 | print_time(); |
| 35 | 35 | } |
| 36 | - return ['x' => ['y' => function () { |
|
| 36 | + return ['x' => ['y' => function() { |
|
| 37 | 37 | return curl('/rest', ['id' => 6, 'sleep' => 2]); |
| 38 | 38 | }]]; |
| 39 | 39 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | define('FAVORITE_REGEX', '/' . trim(fgets(STDIN)) . '/'); |
| 16 | 16 | |
| 17 | 17 | // Listen Twitter UserStreaming on 2 different accounts |
| 18 | -Co::wait(array_map(function ($to) { |
|
| 18 | +Co::wait(array_map(function($to) { |
|
| 19 | 19 | // You have to install (Go)mpyw/twhelp-go or (PHP)mpyw/twhelp. |
| 20 | 20 | // - Go: https://github.com/mpyw/twhelp-go |
| 21 | 21 | // - PHP: https://github.com/mpyw/twhelp |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | exit(1); |
| 25 | 25 | } |
| 26 | 26 | eval(implode($r)); |
| 27 | - return $to->curlStreaming('user', function ($status) use ($to) { |
|
| 27 | + return $to->curlStreaming('user', function($status) use ($to) { |
|
| 28 | 28 | if (isset($status->text)) { |
| 29 | 29 | if (preg_match(FAVORITE_REGEX, htmlspecialchars_decode($status->text, ENT_NOQUOTES))) { |
| 30 | 30 | Co::async($to->curlPost('favorites/create', array( |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | require __DIR__ . '/../vendor/autoload.php'; |
| 4 | 4 | |
| 5 | 5 | use mpyw\Co\Co; |
| 6 | -use mpyw\Co\CURLException; |
|
| 7 | 6 | |
| 8 | 7 | function curl_init_with($url, array $options = [CURLOPT_RETURNTRANSFER => true]) { |
| 9 | 8 | $ch = curl_init($url); |
@@ -18,10 +18,10 @@ |
||
| 18 | 18 | |
| 19 | 19 | var_dump(Co::wait([ |
| 20 | 20 | "google.com HTML" => curl_init_with("https://google.com"), |
| 21 | - "Content-Length of github.com" => function () { |
|
| 21 | + "Content-Length of github.com" => function() { |
|
| 22 | 22 | return strlen(yield curl_init_with("https://github.com")); |
| 23 | 23 | }, |
| 24 | - "Save mpyw's Gravatar Image URL to local" => function () { |
|
| 24 | + "Save mpyw's Gravatar Image URL to local" => function() { |
|
| 25 | 25 | yield curl_init_with( |
| 26 | 26 | (yield get_xpath_async('https://github.com/mpyw')) |
| 27 | 27 | ->evaluate('string(//img[contains(@class,"avatar")]/@src)'), |
@@ -54,14 +54,14 @@ |
||
| 54 | 54 | * - "async" (Co::async calls) |
| 55 | 55 | */ |
| 56 | 56 | private $options = array(); |
| 57 | - private $mh; // curl_multi_init() |
|
| 58 | - private $count = 0; // count(curl_multi_add_handle called) |
|
| 59 | - private $queue = array(); // cURL resources over concurrency limits are temporalily stored here |
|
| 60 | - private $tree = array(); // array<*Stack ID*, mixed> |
|
| 61 | - private $values = array(); // array<*Stack ID*|*cURL ID*, Generator|resource<cURL>> |
|
| 62 | - private $value_to_parent = array(); // array<*Stack ID*|*cURL ID*, *Stack ID*> |
|
| 57 | + private $mh; // curl_multi_init() |
|
| 58 | + private $count = 0; // count(curl_multi_add_handle called) |
|
| 59 | + private $queue = array(); // cURL resources over concurrency limits are temporalily stored here |
|
| 60 | + private $tree = array(); // array<*Stack ID*, mixed> |
|
| 61 | + private $values = array(); // array<*Stack ID*|*cURL ID*, Generator|resource<cURL>> |
|
| 62 | + private $value_to_parent = array(); // array<*Stack ID*|*cURL ID*, *Stack ID*> |
|
| 63 | 63 | private $value_to_children = array(); // array<*Stack ID*, array<*Stack ID*|*cURL ID*, true>> |
| 64 | - private $value_to_keylist = array(); // array<*Stack ID*|*cURL ID*, array<mixed>> |
|
| 64 | + private $value_to_keylist = array(); // array<*Stack ID*|*cURL ID*, array<mixed>> |
|
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Override or get default settings. |