@@ -4,13 +4,12 @@ Async cURL error handling
44curl
55--FILE--
66<?php
7- include "../common/simple_http_server.php " ;
7+ include "../../sapi/cli/tests/php_cli_server.inc " ;
88
99use function Async \spawn ;
1010use function Async \awaitAll ;
1111
12- // Start test server
13- $ server_pid = start_test_server_process (8088 );
12+ php_cli_server_start ();
1413
1514function test_connection_error () {
1615 echo "Testing connection error \n" ;
@@ -37,8 +36,9 @@ function test_connection_error() {
3736function test_server_error () {
3837 echo "Testing server error \n" ;
3938
39+ // Test with invalid URL to trigger an error
4040 $ ch = curl_init ();
41- curl_setopt ($ ch , CURLOPT_URL , get_test_server_url ( ' /error ' ) );
41+ curl_setopt ($ ch , CURLOPT_URL , " http:// " . PHP_CLI_SERVER_ADDRESS . " /nonexistent.php " );
4242 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
4343 curl_setopt ($ ch , CURLOPT_TIMEOUT , 5 );
4444
@@ -50,7 +50,7 @@ function test_server_error() {
5050
5151 echo "HTTP Code: $ http_code \n" ;
5252 echo "Error: " . ($ error ?: "none " ) . "\n" ;
53- echo "Response: $ response \n" ;
53+ echo "Response length: " . strlen ( $ response) . " \n" ;
5454
5555 return $ response ;
5656}
@@ -59,7 +59,7 @@ function test_not_found() {
5959 echo "Testing 404 error \n" ;
6060
6161 $ ch = curl_init ();
62- curl_setopt ($ ch , CURLOPT_URL , get_test_server_url ( ' /nonexistent ' ) );
62+ curl_setopt ($ ch , CURLOPT_URL , " http:// " . PHP_CLI_SERVER_ADDRESS . " /missing.html " );
6363 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
6464 curl_setopt ($ ch , CURLOPT_TIMEOUT , 5 );
6565
@@ -69,7 +69,7 @@ function test_not_found() {
6969 curl_close ($ ch );
7070
7171 echo "HTTP Code: $ http_code \n" ;
72- echo "Response: $ response \n" ;
72+ echo "Response length: " . strlen ( $ response) . " \n" ;
7373
7474 return $ response ;
7575}
@@ -84,9 +84,6 @@ $coroutines = [
8484
8585$ results = awaitAll ($ coroutines );
8686
87- // Stop server
88- stop_test_server_process ($ server_pid );
89-
9087echo "Test end \n" ;
9188?>
9289--EXPECTF--
@@ -97,9 +94,9 @@ Testing 404 error
9794Connection failed as expected
9895Error present: yes
9996Error number: %d
100- HTTP Code: 500
97+ HTTP Code: 404
10198Error: none
102- Response: Internal Server Error
99+ Response length: %d
103100HTTP Code: 404
104- Response: Not Found
101+ Response length: %d
105102Test end
0 commit comments