1--TEST-- 2swoole_socket_coro: ssl client 3--SKIPIF-- 4<?php require __DIR__ . '/../include/skipif.inc'; 5skip_if_no_ssl(); 6skip_if_offline(); 7?> 8--FILE-- 9<?php 10require __DIR__ . '/../include/bootstrap.php'; 11 12use function Swoole\Coroutine\run; 13 14run(function () { 15 $cli = new Swoole\Coroutine\Socket(AF_INET, SOCK_STREAM, 0); 16 $cli->setProtocol(['open_ssl' => true,]); 17 18 if (!$cli->connect('www.baidu.com', 443)) { 19 echo "ERROR\n"; 20 } 21 22 $http = "GET / HTTP/1.1\r\nAccept: */*User-Agent: Lowell-Agent\r\nHost: www.baidu.com\r\nConnection: Keep-Alive\r\n" 23 . "Keep-Alive: on\r\n\r\n"; 24 if (!$cli->send($http)) { 25 echo "ERROR\n"; 26 } 27 28 $content = ''; 29 $length = 0; 30 while (true) { 31 $read = $cli->recv(); 32 if (empty($read)) { 33 var_dump($read); 34 break; 35 } 36 $content .= $read; 37 if ($length == 0) { 38 if (preg_match('#Content-Length: (\d+)#i', $content, $match)) { 39 $length = intval($match[1]); 40 } 41 } 42 $header_length = strpos($content, "\r\n\r\n"); 43 if (strlen($content) == $length + $header_length + 4) { 44 break; 45 } 46 } 47 $cli->close(); 48 Assert::assert(strpos($content, 'map.baidu.com') !== false); 49}); 50?> 51--EXPECT-- 52