Skip to content

Instantly share code, notes, and snippets.

@ecourtial
Last active March 5, 2022 13:33
Show Gist options
  • Save ecourtial/d239cfc27561e98463abd671625ca55c to your computer and use it in GitHub Desktop.
Save ecourtial/d239cfc27561e98463abd671625ca55c to your computer and use it in GitHub Desktop.
Fiber exemple 3-3: CURL call
<?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