12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php declare(strict_types=1);
- use PHPUnit\Framework\TestCase;
- define('APP_ID', 'test');
- define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_CORE_PATH . '/lrlz.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- class TestSwool extends TestCase
- {
- public static function setUpBeforeClass() : void
- {
- Base::run_util();
- }
- public function testCurl()
- {
- Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
- Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_CURL);
- $n = 100;
- $i = 0;
- while($n--)
- {
- go(function () use($i) {
- Log::record("start {$i}",Log::DEBUG);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "http://www.xinhuanet.com/");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- $output = curl_exec($ch);
- if ($output === FALSE) {
- Log::record("index = {$i} CURL Error:" . curl_error($ch),Log::DEBUG);
- }
- curl_close($ch);
- Log::record("index={$i} length=" . strlen($output) . " bytes",Log::DEBUG);
- });
- $i++;
- Coroutine::sleep(.1);
- }
- swoole_event_wait();
- }
- }
|