Skip to content

Instantly share code, notes, and snippets.

@nielsdos
Created June 7, 2024 19:05
Show Gist options
  • Save nielsdos/0feec3721c3b12947c1964a53f75b479 to your computer and use it in GitHub Desktop.
Save nielsdos/0feec3721c3b12947c1964a53f75b479 to your computer and use it in GitHub Desktop.
--TEST--
Test CURL_READFUNC_PAUSE and curl_pause()
--EXTENSIONS--
curl
--FILE--
<?php
include 'server.inc';
$host = curl_cli_server_start();
class CrashingFifo {
public bool $eof = false;
/** @var resource|null Stream context (this is set by PHP) */
public $context;
function stream_open($path, $mode, $options, &$opened_path): bool
{
return true;
}
function stream_read(int $count): false|string|null
{
if ($this->eof)return null;
$this->eof = true;
return str_repeat('x', 3);
}
function stream_eof(): bool {
return $this->eof;
}
}
stream_register_wrapper('fifo', CrashingFifo::class);
$readStream = fopen('fifo://1', 'r');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=input");
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $readStream);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$multi = curl_multi_init();
curl_multi_add_handle($multi, $ch);
do {
curl_multi_exec($multi, $still_running);
} while ($still_running);
fclose($readStream);
unset($multi);
unset($ch);
echo "x\n";
?>
--EXPECT--
string(15) "Foo bar baz qux"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment