Last active
March 5, 2022 13:33
-
-
Save ecourtial/d239cfc27561e98463abd671625ca55c to your computer and use it in GitHub Desktop.
Fiber exemple 3-3: CURL call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is a basic synchronous (blocking) CURL call. | |
*/ | |
declare(strict_types=1); | |
$requestId = $argv[1]; | |
$url = 'http://xxxxx/ping.php?id=' . $requestId; // The target URL uses a sleep to simulate network latency. | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_exec($ch); // CURL is executed in blocking mode, on purpose, for the example. | |
if(curl_error($ch)) { | |
throw new \RuntimeException('CURL ERROR: ' . curl_error($ch)); | |
} | |
exec("touch response_{$requestId}.txt"); // When the request has succeeded, we create an empty file, we will see that later. | |
curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment