Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/curl/tests/bug54798-unix.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function checkForClosedFilePointer($host, $curl_option, $description) {

if (CURLOPT_INFILE == $curl_option) {
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable Expect: 100-continue to prevent libcurl's 1-second delay.

May I ask where the 1 second delay come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expect 100-continue is a flow control mechanism that is not apparently not supported by the PHP development server. Curl waits one second for a 100-continue response and then continues anyway.

https://everything.curl.dev/http/post/expect100.html

Unfortunately, lots of servers in the world do not properly support the Expect: header or do not handle it correctly, so curl only waits 1000 milliseconds for that first response before it continues anyway.

You can avoid the wait entirely by using -H Expect: to remove the header

}

curl_setopt($ch, $curl_option, $fp);
Expand Down
1 change: 1 addition & 0 deletions ext/curl/tests/bug54798.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function checkForClosedFilePointer($host, $curl_option, $description) {

if (CURLOPT_INFILE == $curl_option) {
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);
}

curl_setopt($ch, $curl_option, $fp);
Expand Down
1 change: 1 addition & 0 deletions ext/curl/tests/curl_pause_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $inputHandle = fopen(__FILE__, 'r');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=input");
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);
curl_setopt($ch, CURLOPT_READFUNCTION, new Input);
curl_setopt($ch, CURLOPT_INFILE, $inputHandle);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Expand Down
3 changes: 2 additions & 1 deletion ext/curl/tests/curl_read_function_error_on_int.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ include 'server.inc';
$host = curl_cli_server_start();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "{$host}/get.php?test=post");
curl_setopt($ch, CURLOPT_POST, ['f' => 'f']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_READFUNCTION, "custom_readfunction" );

Expand Down
1 change: 1 addition & 0 deletions ext/curl/tests/curl_readfunc_abort.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $host = curl_cli_server_start();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);
curl_setopt($ch, CURLOPT_READFUNCTION, function () {
return CURL_READFUNC_ABORT;
});
Expand Down
1 change: 1 addition & 0 deletions ext/curl/tests/curl_readfunction_throws_abort.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $ch = curl_init("{$host}/get.inc");

$file = new CURLFile(__DIR__ . '/curl_testdata1.txt');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);

echo "Test: read function throws exception\n";
curl_setopt($ch, CURLOPT_READFUNCTION,
Expand Down
5 changes: 4 additions & 1 deletion ext/curl/tests/curl_setopt_ssl.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ if ($process === false) {
}
try {
// Give the server time to start
sleep(1);
for ($i = 0; $i < 100; $i++) {

@NickSdot NickSdot Aug 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for ($i = 0; $i < 100; $i++) {
for ($i = 0; $i < 50; $i++) {

Maybe 50 is enough? Would match the previous 1s; fsockopen already adds extra.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 50 (or even 10 or 20) would work. 100 is just a number that's high but not infinite. In normal operation this loop will only iterate a couple of times, and 50 or 100 is never reached.

If you are worried about the time this test takes when the server fails to start, perhaps a better way is to get the server process status with proc_get_status and stop the test when the server is no longer running.

if (@fsockopen('127.0.0.1', $port)) break;
usleep(20000);
}

echo "case 1: client cert and key from string\n";
$ch = curl_init("https://127.0.0.1:$port/");
Expand Down
6 changes: 3 additions & 3 deletions ext/curl/tests/server.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function curl_cli_server_start() {
$bound = null;
stream_set_blocking($pipes[2], false);
for ($i = 0; $i < 60; $i++) {
usleep(50000); // 50ms per try
usleep(20000); // 20ms per try
$status = proc_get_status($handle);
if (empty($status['running'])) {
echo "Server is not running\n";
Expand Down Expand Up @@ -45,7 +45,6 @@ function curl_cli_server_start() {
// it might not be listening yet...need to wait until fsockopen() call returns
$error = "Unable to connect to server\n";
for ($i=0; $i < 60; $i++) {
usleep(50000); // 50ms per try
$status = proc_get_status($handle);
$fp = @fsockopen("tcp://$bound");
// Failure, the server is no longer running
Expand All @@ -58,6 +57,7 @@ function curl_cli_server_start() {
$error = '';
break;
}
usleep(20000); // 20ms per try
}

if ($fp) {
Expand All @@ -79,7 +79,7 @@ function curl_cli_server_start() {
if (!($status && $status['running'])) {
break;
}
usleep(50000);
usleep(20000);
}
},
$handle
Expand Down
Loading