Skip to content

Commit 937115f

Browse files
committed
Merge branch 'PHP-7.0' into PHP-7.1
2 parents a49675f + 2d51267 commit 937115f

File tree

5 files changed

+127
-158
lines changed

5 files changed

+127
-158
lines changed

ext/curl/tests/bug48203_multi-win32.phpt

Lines changed: 0 additions & 89 deletions
This file was deleted.

ext/curl/tests/bug48203_multi.phpt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ Variation of bug #48203 with curl_multi_exec (Crash when file pointers passed to
33
--SKIPIF--
44
<?php
55
include 'skipif.inc';
6-
if(substr(PHP_OS, 0, 3) == 'WIN' ) {
7-
die('skip not for Windows');
8-
}
96
?>
107
--FILE--
118
<?php
129
include 'server.inc';
13-
function checkForClosedFilePointer($curl_option, $description) {
10+
function checkForClosedFilePointer($target_url, $curl_option, $description) {
1411
$fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w');
1512

1613
$ch1 = curl_init();
@@ -19,7 +16,7 @@ function checkForClosedFilePointer($curl_option, $description) {
1916
$options = array(
2017
CURLOPT_RETURNTRANSFER => 1,
2118
$curl_option => $fp,
22-
CURLOPT_URL => curl_cli_server_start()
19+
CURLOPT_URL => $target_url,
2320
);
2421

2522
// we also need to set CURLOPT_VERBOSE to test CURLOPT_STDERR properly
@@ -50,38 +47,45 @@ function checkForClosedFilePointer($curl_option, $description) {
5047
curl_multi_remove_handle($mh, $ch2);
5148
curl_multi_close($mh);
5249

50+
// Force curl to output results
51+
fflush(STDERR);
52+
fflush(STDOUT);
53+
5354
echo "Ok for $description\n";
5455
}
5556

5657
$options_to_check = array(
5758
"CURLOPT_STDERR", "CURLOPT_WRITEHEADER", "CURLOPT_FILE", "CURLOPT_INFILE"
5859
);
5960

61+
$target_url = curl_cli_server_start();
6062
foreach($options_to_check as $option) {
61-
checkForClosedFilePointer(constant($option), $option);
63+
checkForClosedFilePointer($target_url, constant($option), $option);
6264
}
6365

6466
?>
6567
--CLEAN--
6668
<?php @unlink(dirname(__FILE__) . '/bug48203.tmp'); ?>
6769
--EXPECTF--
68-
Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug48203_multi.php on line 36
70+
Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %s on line %d
6971

70-
Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug48203_multi.php on line 36
72+
Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %s on line %d
7173
%A
7274
Ok for CURLOPT_STDERR
73-
%A
74-
Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug48203_multi.php on line 36
7575

76-
Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug48203_multi.php on line 36
76+
Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %s on line %d
77+
78+
Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %s on line %d
7779
Ok for CURLOPT_WRITEHEADER
7880

79-
Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
81+
Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %s on line %d
8082

81-
Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
82-
%AOk for CURLOPT_FILE
83+
Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %s on line %d
84+
Hello World!
85+
Hello World!Hello World!
86+
Hello World!Ok for CURLOPT_FILE
8387

84-
Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
88+
Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %s on line %d
8589

86-
Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
90+
Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %s on line %d
8791
Ok for CURLOPT_INFILE

ext/curl/tests/server.inc

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,64 @@ function curl_cli_server_start() {
99
return getenv('PHP_CURL_HTTP_REMOTE_SERVER');
1010
}
1111

12-
$php_executable = getenv('TEST_PHP_EXECUTABLE');
13-
$doc_root = __DIR__;
14-
$router = "responder/get.php";
15-
16-
$descriptorspec = array(
17-
0 => STDIN,
18-
1 => STDOUT,
19-
2 => STDERR,
20-
);
21-
22-
if (substr(PHP_OS, 0, 3) == 'WIN') {
23-
$cmd = "{$php_executable} -t {$doc_root} -n -S " . PHP_CURL_SERVER_ADDRESS;
12+
$php_executable = getenv('TEST_PHP_EXECUTABLE');
13+
$doc_root = __DIR__;
14+
$router = "responder/get.php";
15+
16+
$descriptorspec = array(
17+
0 => STDIN,
18+
1 => STDOUT,
19+
2 => STDERR,
20+
);
21+
22+
if (substr(PHP_OS, 0, 3) == 'WIN') {
23+
$cmd = "{$php_executable} -t {$doc_root} -n -S " . PHP_CURL_SERVER_ADDRESS;
24+
$cmd .= " {$router}";
25+
$handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true));
26+
} else {
27+
$cmd = "exec {$php_executable} -t {$doc_root} -n -S " . PHP_CURL_SERVER_ADDRESS;
2428
$cmd .= " {$router}";
25-
$handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true));
26-
} else {
27-
$cmd = "exec {$php_executable} -t {$doc_root} -n -S " . PHP_CURL_SERVER_ADDRESS;
28-
$cmd .= " {$router}";
29-
$cmd .= " 2>/dev/null";
30-
31-
$handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root);
32-
}
29+
$cmd .= " 2>/dev/null";
30+
31+
$handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root);
32+
}
3333

34-
// note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.'
35-
// it might not be listening yet...need to wait until fsockopen() call returns
36-
$i = 0;
37-
while (($i++ < 30) && !($fp = @fsockopen(PHP_CURL_SERVER_HOSTNAME, PHP_CURL_SERVER_PORT))) {
38-
usleep(10000);
34+
// note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.'
35+
// it might not be listening yet...need to wait until fsockopen() call returns
36+
$error = "Unable to connect to servers\n";
37+
for ($i=0; $i < 60; $i++) {
38+
usleep(25000); // 25ms per try
39+
$status = proc_get_status($handle);
40+
$fp = @fsockopen(PHP_CURL_SERVER_HOSTNAME, PHP_CURL_SERVER_PORT);
41+
// Failure, the server is no longer running
42+
if (!($status && $status['running'])) {
43+
$error = "Server is not running\n";
44+
break;
45+
}
46+
// Success, Connected to servers
47+
if ($fp) {
48+
$error = '';
49+
break;
50+
}
3951
}
4052

4153
if ($fp) {
4254
fclose($fp);
4355
}
4456

45-
register_shutdown_function(
46-
function($handle) use($router) {
47-
proc_terminate($handle);
48-
},
49-
$handle
50-
);
51-
// don't bother sleeping, server is already up
52-
// server can take a variable amount of time to be up, so just sleeping a guessed amount of time
53-
// does not work. this is why tests sometimes pass and sometimes fail. to get a reliable pass
54-
// sleeping doesn't work.
57+
if ($error) {
58+
echo $error;
59+
proc_terminate($handle);
60+
exit(1);
61+
}
62+
63+
register_shutdown_function(
64+
function($handle) use($router) {
65+
proc_terminate($handle);
66+
},
67+
$handle
68+
);
69+
5570
return PHP_CURL_SERVER_ADDRESS;
5671
}
72+

sapi/cli/tests/bug67429.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ include "skipif.inc";
88
<?php
99
include "php_cli_server.inc";
1010

11+
// This creates a new server for each response code
1112
foreach ([308, 426] as $code) {
12-
php_cli_server_start(<<<PHP
13+
$proc_handle = php_cli_server_start(<<<PHP
1314
http_response_code($code);
1415
PHP
1516
);
@@ -34,6 +35,10 @@ HEADER
3435
}
3536

3637
fclose($fp);
38+
// Shutdown the servers or another server may not be able to start
39+
// because of the this server still being bound to the port
40+
41+
php_cli_server_stop($proc_handle);
3742
}
3843
?>
3944
--EXPECTF--

sapi/cli/tests/php_cli_server.inc

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,62 @@ function php_cli_server_start($code = 'echo "Hello world";', $router = 'index.ph
3333

3434
$handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root);
3535
}
36-
37-
// note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.'
38-
// it might not be listening yet...need to wait until fsockopen() call returns
39-
$i = 0;
40-
while (($i++ < 30) && !($fp = @fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT))) {
41-
usleep(10000);
36+
37+
// note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.'
38+
// it might not be listening yet...need to wait until fsockopen() call returns
39+
$error = "Unable to connect to servers\n";
40+
for ($i=0; $i < 60; $i++) {
41+
usleep(25000); // 25ms per try
42+
$status = proc_get_status($handle);
43+
$fp = @fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT);
44+
// Failure, the server is no longer running
45+
if (!($status && $status['running'])) {
46+
$error = "Server is not running\n";
47+
break;
48+
}
49+
// Success, Connected to servers
50+
if ($fp) {
51+
$error = '';
52+
break;
53+
}
4254
}
4355

4456
if ($fp) {
4557
fclose($fp);
4658
}
4759

48-
register_shutdown_function(
49-
function($handle) use($router) {
50-
proc_terminate($handle);
51-
@unlink(__DIR__ . "/{$router}");
52-
},
53-
$handle
54-
);
55-
// don't bother sleeping, server is already up
56-
// server can take a variable amount of time to be up, so just sleeping a guessed amount of time
57-
// does not work. this is why tests sometimes pass and sometimes fail. to get a reliable pass
58-
// sleeping doesn't work.
60+
if ($error) {
61+
echo $error;
62+
proc_terminate($handle);
63+
exit(1);
64+
}
65+
66+
register_shutdown_function(
67+
function($handle) use($router) {
68+
proc_terminate($handle);
69+
@unlink(__DIR__ . "/{$router}");
70+
},
71+
$handle
72+
);
73+
74+
return $handle;
75+
}
76+
77+
function php_cli_server_stop($handle) {
78+
$success = FALSE;
79+
if ($handle) {
80+
proc_terminate($handle);
81+
/* Wait for server to shutdown */
82+
for ($i = 0; $i < 60; $i++) {
83+
$status = proc_get_status($handle);
84+
if (!($status && $status['running'])) {
85+
$success = TRUE;
86+
break;
87+
}
88+
usleep(25000);
89+
}
90+
}
91+
return $success;
5992
}
6093
?>
6194

0 commit comments

Comments
 (0)