mirror of
https://github.com/php/php-src.git
synced 2024-11-28 04:14:26 +08:00
Make the ftp and stream tests more reliable.
The tests can sometimes fail because it chooses a passive port for ftp that is already in use. This makes the test attempt multiple times to find a free port.
This commit is contained in:
parent
5432d6f982
commit
3b91ed112f
@ -7,7 +7,7 @@ $context = stream_context_create(array('ssl' => array('local_cert' => dirname(__
|
||||
for ($i=0; $i<10 && !$socket; ++$i) {
|
||||
$port = rand(50000, 65535);
|
||||
|
||||
@$socket = stream_socket_server("tcp://127.0.0.1:$port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
|
||||
$socket = @stream_socket_server("tcp://127.0.0.1:$port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
|
||||
}
|
||||
//set anther random port that is not the same as $port
|
||||
do{
|
||||
@ -402,15 +402,29 @@ if ($pid) {
|
||||
|
||||
}elseif (preg_match('/^PASV/', $buf, $matches)) {
|
||||
$pasv=true;
|
||||
$p2 = $pasv_port % ((int) 1 << 8);
|
||||
$p1 = ($pasv_port-$p2)/((int) 1 << 8);
|
||||
$host = "127.0.0.1";
|
||||
$i=0;
|
||||
|
||||
do {
|
||||
if (!empty($ssl)) {
|
||||
$soc = stream_socket_server("tcp://127.0.0.1:$pasv_port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
|
||||
$soc = @stream_socket_server("tcp://127.0.0.1:$pasv_port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
|
||||
} else {
|
||||
$soc = stream_socket_server("tcp://127.0.0.1:$pasv_port");
|
||||
$soc = @stream_socket_server("tcp://127.0.0.1:$pasv_port");
|
||||
}
|
||||
/* Could bind port, Try another port */
|
||||
if (!$soc) {
|
||||
$pasv_port = rand(50000, 65535);
|
||||
}
|
||||
$i++;
|
||||
} while ($i<10 && !$soc);
|
||||
|
||||
if (!$soc) {
|
||||
echo "$errstr ($errno)\n";
|
||||
die("could not bind passive port\n");
|
||||
}
|
||||
|
||||
$p2 = $pasv_port % ((int) 1 << 8);
|
||||
$p1 = ($pasv_port-$p2)/((int) 1 << 8);
|
||||
fputs($s, "227 Entering Passive Mode. (127,0,0,1,{$p1},{$p2})\r\n");
|
||||
|
||||
$pasvs = stream_socket_accept($soc,10);
|
||||
|
Loading…
Reference in New Issue
Block a user