├── examples ├── http │ ├── empty.txt │ ├── UPPER.TXT │ ├── moc.moc │ ├── test.txt │ ├── post.data │ ├── redirect.php │ ├── raw.php │ ├── download.php │ ├── static_handler.php │ └── no-compression.php ├── ssl │ ├── swoole.log │ ├── gen_cert.md │ ├── co_client.php │ ├── http_client.php │ ├── websocket_client.html │ └── passphrase.php ├── www │ ├── file2.txt │ ├── file1.txt │ ├── index.txt │ ├── dir1 │ │ ├── file1.txt │ │ └── file2.txt │ ├── dir2 │ │ ├── file1.txt │ │ ├── file2.txt │ │ └── index.txt │ └── index.html ├── http2 │ ├── test.html │ └── streaming.php ├── php │ ├── error.php │ ├── tick.php │ ├── func.php │ ├── exception.php │ ├── stream_client.php │ ├── inotify.php │ └── socket_client.php ├── length │ └── config.php ├── misc │ ├── get_local_mac.php │ ├── version.php │ └── get_local_ip.php ├── test.jpg ├── runtime │ ├── include.php │ ├── sleep.php │ ├── unlink.phpt │ ├── rename.phpt │ ├── gethostbyname.php │ ├── mkdir.php │ ├── read.php │ ├── time_sleep_until.php │ ├── sync.php │ ├── sqlite.php │ ├── file.php │ ├── stream.php │ ├── curl.php │ ├── ssl.php │ └── odbc.php ├── coroutine │ ├── statvfs.php │ ├── exec.php │ ├── scheduler.php │ ├── stack │ │ └── 2.php │ ├── coro_empty.php │ ├── gethostbyname.php │ ├── coro_include.php │ ├── redis │ │ ├── eval.php │ │ ├── request.php │ │ ├── auth.php │ │ ├── get.php │ │ ├── pub.php │ │ ├── serialize.php │ │ ├── multi.php │ │ ├── pipeline.php │ │ └── sub.php │ ├── deadlock.php │ ├── fwrite.php │ ├── fread.php │ ├── coro_set_stack_size.php │ ├── coro_sleep.php │ ├── coro_gethost.php │ ├── behavior │ │ ├── goto.php │ │ ├── foreach.php │ │ ├── do-while.php │ │ └── while2.php │ ├── util │ │ ├── resume002.php │ │ └── resume001.php │ ├── exit_with_status.php │ ├── sleep.php │ ├── stack.php │ ├── cancel_throw.php │ ├── timer_test.php │ ├── coro_nested_empty.php │ ├── exception │ │ └── empty.php │ ├── mysql_escape.php │ ├── coro_util.php │ ├── mysql_execute_empty.php │ ├── http │ │ └── write_func.php │ ├── mysql_unixsocket.php │ ├── redis_subscribe.php │ ├── pdo │ │ └── pdo_persistent.phpt │ ├── socket │ │ ├── sendto.php │ │ └── accept.php │ ├── coro_call_user.php │ ├── http_download.php │ ├── exit_in_coroutine.php │ ├── http_client.php │ ├── list_coroutines.php │ ├── coro_invoke.php │ ├── coro_destruct.php │ ├── select │ │ ├── 9.php │ │ ├── poptimeout.php │ │ ├── 4.php │ │ ├── 2.php │ │ └── test.php │ ├── proc_open.php │ ├── tcp_backend_serv.php │ ├── coro_array_map.php │ ├── fgets.php │ ├── mysql_prepare_2.php │ ├── defer.php │ ├── mysql_query.php │ └── server │ │ └── tcp.php ├── process │ ├── set_cpu_affinity.php │ ├── echo.py │ ├── stdin_stdout.php │ ├── test.php │ ├── msg_push.php │ ├── msg_pop.php │ ├── alarm.php │ ├── client3.php │ ├── msgqueue_client.php │ ├── daemon.php │ ├── pool_socket.php │ ├── python.php │ ├── select.php │ ├── exec.php │ ├── msgqueue_pool.php │ ├── client.php │ └── close.php ├── event │ ├── stdin.php │ ├── test.php │ ├── cycle.php │ ├── inotify.php │ └── stream.php ├── stdext │ ├── typed_array.php │ ├── foreach.php │ └── typed_array_map.php ├── server │ ├── hot_update_class.php │ ├── single.php │ ├── listen_1k_port.php │ ├── dispatch_stream.php │ ├── dispatch_func.php │ ├── reload_force2.php │ └── reload_force.php ├── multicast │ └── client.php ├── atomic │ ├── test.php │ ├── long.php │ └── wait.php ├── timer │ ├── enable_coroutine.php │ └── clear.php ├── process_pool │ └── send.php ├── udp │ ├── client.php │ └── server.php ├── client │ ├── udp_sync.php │ ├── test.txt │ ├── long_tcp.php │ ├── simple.php │ └── recv_1m.php ├── thread │ ├── run_test.php │ ├── test.php │ ├── argv.php │ ├── lock.php │ ├── map.php │ ├── exit.php │ ├── array.php │ ├── nested_map.php │ ├── socket.php │ ├── pipe.php │ └── benchmark.php ├── ipv6 │ ├── udp_client.php │ ├── tcp_client.php │ └── udp_server.php ├── unixsock │ ├── dgram_client.php │ └── stream_client.php ├── dtls │ └── client.php ├── tracer │ ├── co.php │ └── gc.php ├── curl │ └── server.php ├── cpp │ └── Makefile ├── websocket │ └── client.html ├── socket_coro │ └── client.php └── table │ └── usage.php ├── scripts ├── .gitignore ├── debug │ ├── swoole_table_implements.php │ └── swoole_info.php ├── code-stats.sh ├── rename.php ├── pecl-install.sh ├── simple-compile.sh ├── install-deps-on-ubuntu.sh ├── docker-thread-route.sh ├── clear.sh └── docker-iouring-route.sh ├── thirdparty ├── nghttp2 │ └── LICENSE ├── php84 │ ├── ftp │ │ └── CREDITS │ └── pdo_firebird │ │ └── CREDITS ├── pdo_oci │ └── CREDITS ├── php85 │ └── pdo_firebird │ │ └── CREDITS ├── hiredis │ └── fmacros.h └── nlohmann │ └── detail │ └── meta │ └── void_t.hpp ├── tests ├── include │ ├── ssl_certs │ │ ├── ca.srl │ │ ├── client.pem │ │ ├── server.pem │ │ └── dhparams.pem │ ├── api │ │ ├── syntax_error.txt │ │ ├── swoole_server │ │ │ └── testsendfile.txt │ │ ├── test_classes │ │ │ ├── A2.php │ │ │ ├── A.php │ │ │ └── B.php │ │ ├── swoole_thread │ │ │ ├── sleep.php │ │ │ └── putenv.php │ │ ├── swoole_timer │ │ │ └── multi_timer.php │ │ ├── swoole_http_server │ │ │ ├── simple_http_server.php │ │ │ └── http_server_without_response.php │ │ ├── swoole_client │ │ │ └── connect_timeout.php │ │ └── swoole_websocket_server │ │ │ └── send_small_request_data.php │ └── lib │ │ └── src │ │ ├── Redis │ │ └── DBConnectException.php │ │ └── ThreadManager.php ├── swoole_curl │ ├── upload │ │ ├── curl_testdata1.txt │ │ └── curl_testdata2.txt │ ├── template │ └── multi │ │ ├── no_hook.phpt │ │ ├── 1.phpt │ │ └── 2.phpt ├── swoole_process │ ├── echo.py │ ├── ctor.phpt │ ├── pop.phpt │ ├── start.phpt │ ├── freeQueue.phpt │ ├── exit.phpt │ ├── redirect.phpt │ ├── null_callback.phpt │ ├── useQueue.phpt │ ├── kill.phpt │ ├── process_id.phpt │ ├── setaffinity.phpt │ ├── exec.phpt │ ├── coro │ │ └── start.phpt │ ├── getaffinity.phpt │ └── write.phpt ├── swoole_ssh2 │ ├── testkey_ed25519.pub │ ├── ssh2_auth.phpt │ ├── testkey_ed25519 │ └── bug79631.phpt ├── swoole_runtime │ ├── file_hook │ │ ├── a.inc │ │ ├── b.inc │ │ └── include.phpt │ ├── sockets │ │ └── basic │ │ │ ├── ipv6_skipif.inc │ │ │ ├── mcast_helpers.php.inc │ │ │ └── socket_accept_failure.phpt │ ├── get_hook_flags.phpt │ ├── hook_default.phpt │ ├── out_of_coroutine.phpt │ ├── unsafe │ │ └── pcntl_fork.phpt │ ├── proc │ │ └── proc_open_pipes.inc │ ├── hook_enable_coroutine.phpt │ ├── hook_set_flags.phpt │ ├── stream_context_pass_null.phpt │ ├── library.phpt │ └── file_lock │ │ └── lock_nb.phpt ├── CONTRIBUTION ├── swoole_global │ ├── closed_stdout.phpt │ ├── function_alias.phpt │ ├── unset_property_03.phpt │ ├── unset_property_01.phpt │ ├── unset_property_02.phpt │ └── too_many_objects.phpt ├── swoole_function │ ├── swoole_clear_dns_cache.phpt │ ├── swoole_cpu_num.phpt │ ├── swoole_version.phpt │ ├── swoole_get_local_mac.phpt │ ├── swoole_get_local_ip.phpt │ └── swoole_set_process_name.phpt ├── swoole_client_async │ ├── connect_twice.phpt │ └── enableSSL_bad_callback.phpt ├── swoole_coroutine │ ├── user_coroutine_2.phpt │ ├── max_num_limit.phpt │ ├── empty.phpt │ ├── exit_84.phpt │ ├── bug_5699.phpt │ ├── cid.phpt │ ├── dnslookup_5.phpt │ ├── create_after_rshutdown.phpt │ ├── dnslookup_query_hosts.phpt │ ├── getElasped.phpt │ ├── output │ │ ├── ob_main.phpt │ │ └── create.phpt │ ├── current.phpt │ ├── dnslookup_3.phpt │ ├── nested_empty.phpt │ ├── dnslookup_1.phpt │ ├── new_process.phpt │ ├── new_server.phpt │ ├── dnslookup_ipv6.phpt │ ├── resume_loop.phpt │ ├── array_walk.phpt │ ├── bailout │ │ └── error.phpt │ ├── dnslookup_2.phpt │ ├── call_user_func_array.phpt │ ├── nested1.phpt │ ├── nested2.phpt │ └── nested3.phpt ├── swoole_timer │ ├── swoole_timer_list_alias.phpt │ ├── enable_coroutine.phpt │ ├── greater_than_0.phpt │ ├── not_exist.phpt │ ├── bug_4794_7.phpt │ ├── next_round.phpt │ ├── verify.phpt │ └── bug_4794_5.phpt ├── swoole_table │ ├── create_10k_object.phpt │ ├── getMemorySize_1.phpt │ └── bug_2263.phpt ├── swoole_thread │ ├── empty_args.phpt │ ├── fatal_error_2.inc │ ├── server │ │ └── functions.inc │ ├── fatal_error_1.inc │ ├── map2array.phpt │ └── yield.phpt ├── swoole_coroutine_system │ ├── sleep.phpt │ ├── readfile.phpt │ ├── gethostbyname.phpt │ └── gethostbyname_ipv6.phpt ├── swoole_ftp │ ├── ftp_connect_001.phpt │ ├── ftp_constructor.phpt │ ├── ftp_pasv.phpt │ ├── bug27809.phpt │ ├── ftp_alloc_basic1.phpt │ ├── ftp_exec_basic.phpt │ ├── ftp_mlsd_missing_directory.phpt │ ├── ftp_rmdir_basic.phpt │ ├── bug7216.phpt │ ├── ftp_chmod_basic.phpt │ ├── ftp_rawlist_basic2.phpt │ ├── filesize_large.phpt │ ├── ftp_mlsd_empty_directory.phpt │ ├── ftp_alloc_basic2.phpt │ └── ftp_nb_put.phpt ├── swoole_event │ ├── defer_without_io.phpt │ ├── simple.phpt │ ├── deprecated_event_wait.phpt │ └── dispatch.phpt ├── swoole_server_coro │ └── random_port.phpt ├── swoole_http_server_coro │ └── random_port.phpt ├── swoole_library │ ├── database │ │ ├── pdo.phpt │ │ ├── mysqli.phpt │ │ └── redis.phpt │ └── exec │ │ ├── shell_exec │ │ └── 1.phpt │ │ └── exec │ │ └── 1.phpt ├── swoole_coroutine_wait_group │ └── empty.phpt ├── swoole_pdo_sqlite │ └── pdo_sqlite.inc ├── template ├── swoole_client_coro │ ├── connect_with_dns.phpt │ ├── close_twice.phpt │ ├── connect_dns_timeout.phpt │ └── getsockname.phpt ├── swoole_lock │ ├── lock_nb.phpt │ └── lock_timeout.phpt ├── swoole_channel_coro │ ├── pop_timeout1.phpt │ ├── pop_close1.phpt │ ├── pop_timeout5.phpt │ ├── push_close1.phpt │ ├── push_timeout3.phpt │ ├── 10.phpt │ └── bug_1947.phpt ├── swoole_pdo_firebird │ └── pdo_firebird.inc ├── swoole_server │ ├── ssl │ │ └── code │ │ │ └── client.js │ └── listen_fail.phpt ├── swoole_stdext │ ├── string_method │ │ ├── 1.phpt │ │ ├── json.phpt │ │ └── marshal.phpt │ ├── typed_array │ │ ├── 0.phpt │ │ ├── sort.phpt │ │ ├── 8.phpt │ │ ├── 9.phpt │ │ └── resource.phpt │ └── array_method │ │ └── 1.phpt ├── swoole_socket_coro │ ├── getsockname.phpt │ ├── fd.phpt │ └── ssl.phpt ├── swoole_client_sync │ ├── connect_2.phpt │ ├── connect_1.phpt │ └── enableSSL_2.phpt ├── swoole_http2_client_coro │ └── bug_5127.phpt ├── swoole_process_pool │ ├── shutdown.phpt │ └── master_pid.phpt ├── swoole_coroutine_scheduler │ └── getOptions.phpt ├── swoole_coroutine_util │ ├── fread.phpt │ ├── exec_sleep.phpt │ └── exec.phpt ├── swoole_atomic │ └── atomic.phpt ├── swoole_pdo_odbc │ └── server_info.phpt ├── swoole_pdo_oracle │ └── pdo_oracle.inc └── swoole_redis_server │ └── getHandler.phpt ├── tools ├── composer.json ├── export.php ├── rename.php ├── build-library.php ├── get-ip-info.php ├── gen-data.php ├── show-big-files.php └── send-http-data.php ├── .gitattributes ├── php-cs-fix ├── docs ├── CODE-STYLE.md └── CPPLINT.cfg ├── codecov.yml └── ext-src └── stubs ├── php_swoole_thread_barrier.stub.php ├── php_swoole_tracer.stub.php ├── php_swoole_name_resolver.stub.php ├── php_swoole_coroutine_lock.stub.php ├── php_swoole_runtime.stub.php ├── php_swoole_lock.stub.php ├── php_swoole_thread_lock.stub.php ├── php_swoole_redis_server.stub.php ├── php_swoole_thread_queue.stub.php ├── php_swoole_coroutine_scheduler.stub.php ├── php_swoole_thread_barrier_arginfo.h ├── php_swoole_http_request.stub.php ├── php_swoole_channel_coro.stub.php ├── php_swoole_server_port.stub.php ├── php_swoole_http_server_coro.stub.php ├── php_swoole_timer.stub.php └── php_swoole_ex.stub.php /examples/http/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/ssl/swoole.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/www/file2.txt: -------------------------------------------------------------------------------- 1 | file2 -------------------------------------------------------------------------------- /scripts/.gitignore: -------------------------------------------------------------------------------- 1 | data 2 | -------------------------------------------------------------------------------- /examples/www/file1.txt: -------------------------------------------------------------------------------- 1 | file1.txt -------------------------------------------------------------------------------- /examples/www/index.txt: -------------------------------------------------------------------------------- 1 | index.txt -------------------------------------------------------------------------------- /examples/www/dir1/file1.txt: -------------------------------------------------------------------------------- 1 | dir1/file1 -------------------------------------------------------------------------------- /examples/www/dir1/file2.txt: -------------------------------------------------------------------------------- 1 | dir1/file2 -------------------------------------------------------------------------------- /examples/www/dir2/file1.txt: -------------------------------------------------------------------------------- 1 | dir2/file1 -------------------------------------------------------------------------------- /examples/http/UPPER.TXT: -------------------------------------------------------------------------------- 1 | HELLO WORLD! 2 | -------------------------------------------------------------------------------- /examples/http/moc.moc: -------------------------------------------------------------------------------- 1 | this is moc.moc 2 | -------------------------------------------------------------------------------- /examples/http/test.txt: -------------------------------------------------------------------------------- 1 | hello world! 2 | -------------------------------------------------------------------------------- /examples/http2/test.html: -------------------------------------------------------------------------------- 1 |

Test

2 | -------------------------------------------------------------------------------- /examples/www/dir2/file2.txt: -------------------------------------------------------------------------------- 1 | dir2/file2.txt -------------------------------------------------------------------------------- /examples/www/dir2/index.txt: -------------------------------------------------------------------------------- 1 | dir2/index.txt -------------------------------------------------------------------------------- /thirdparty/nghttp2/LICENSE: -------------------------------------------------------------------------------- 1 | See COPYING 2 | -------------------------------------------------------------------------------- /examples/php/error.php: -------------------------------------------------------------------------------- 1 | test(); 4 | -------------------------------------------------------------------------------- /tests/include/ssl_certs/ca.srl: -------------------------------------------------------------------------------- 1 | BC864F1DFA88521C 2 | -------------------------------------------------------------------------------- /tests/swoole_curl/upload/curl_testdata1.txt: -------------------------------------------------------------------------------- 1 | CURL1 2 | -------------------------------------------------------------------------------- /tests/swoole_curl/upload/curl_testdata2.txt: -------------------------------------------------------------------------------- 1 | CURL2 2 | -------------------------------------------------------------------------------- /tests/include/api/syntax_error.txt: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /tests/include/api/swoole_thread/sleep.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | index.html 7 | 8 | -------------------------------------------------------------------------------- /php-cs-fix: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | ./tests/include/lib/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --using-cache=no --verbose $1 3 | -------------------------------------------------------------------------------- /tests/swoole_ssh2/testkey_ed25519.pub: -------------------------------------------------------------------------------- 1 | ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHQbANGMFPc0QrUsTjxP4SUXqgW8eYme1DlxlAcFWUMC rango@swoole.com 2 | -------------------------------------------------------------------------------- /examples/runtime/unlink.phpt: -------------------------------------------------------------------------------- 1 | '); 3 | 4 | $list[] = 123; 5 | $list[] = 345; 6 | $list[] = 'hello'; // 异常 7 | 8 | -------------------------------------------------------------------------------- /scripts/debug/swoole_table_implements.php: -------------------------------------------------------------------------------- 1 | push($msg); 5 | var_dump($ret); 6 | -------------------------------------------------------------------------------- /examples/runtime/gethostbyname.php: -------------------------------------------------------------------------------- 1 | '); 3 | 4 | $arr[] = 1; 5 | // $arr[0] += 10; 6 | // assert($arr[0] == 11); 7 | $arr[0] .= "hello world"; -------------------------------------------------------------------------------- /examples/stdext/typed_array_map.php: -------------------------------------------------------------------------------- 1 | '); 3 | 4 | $list["hello"] = 123; 5 | $list[] = 345; 6 | $list["hello"] = 'hello'; 7 | -------------------------------------------------------------------------------- /tests/include/lib/src/Redis/DBConnectException.php: -------------------------------------------------------------------------------- 1 | run(function ($host) { 5 | 6 | 7 | }); -------------------------------------------------------------------------------- /tools/export.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 1]); 3 | 4 | co::create(function () { 5 | echo "no coro exit\n"; 6 | }); 7 | echo "exec file end\n"; 8 | -------------------------------------------------------------------------------- /docs/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | set noparent 2 | filter=-build/include_alpha,-build/include_subdir,-build/include_what_you_use,-legal/copyright,-readability/nolint 3 | braces=4 4 | linelength=120 5 | -------------------------------------------------------------------------------- /examples/runtime/mkdir.php: -------------------------------------------------------------------------------- 1 | 2 | Twosee @ Swoole Group 3 | Xiaofeng Chu @ Zan Group 4 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - "src/core/error.cc" 3 | - "thirdparty/hiredis/*" 4 | - "thirdparty/llhttp/*" 5 | 6 | coverage: 7 | range: 60..80 8 | round: down 9 | precision: 2 10 | -------------------------------------------------------------------------------- /examples/coroutine/gethostbyname.php: -------------------------------------------------------------------------------- 1 | connect('224.10.20.30', 9905); 4 | $client->send("hello world"); 5 | echo $client->recv() . "\n"; 6 | sleep(1); 7 | -------------------------------------------------------------------------------- /scripts/debug/swoole_info.php: -------------------------------------------------------------------------------- 1 | swoole_version(), 4 | 'cpu_num' => swoole_cpu_num(), 5 | 'local_mac' => swoole_get_local_mac(), 6 | 'local_ip' => swoole_get_local_ip() 7 | ]); 8 | -------------------------------------------------------------------------------- /examples/coroutine/coro_include.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 6379); 5 | $res = $redis->eval("return redis.call('get', 'key')"); 6 | var_dump($res); 7 | }); 8 | -------------------------------------------------------------------------------- /examples/coroutine/redis/request.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 6379); 5 | $res = $redis->request(['object', 'encoding', 'key1']); 6 | var_dump($res); 7 | }); 8 | -------------------------------------------------------------------------------- /examples/process/msg_pop.php: -------------------------------------------------------------------------------- 1 | on('Message', function (Pool $pool, string $data) { 6 | var_dump($data); 7 | }); 8 | $pool->start(); 9 | -------------------------------------------------------------------------------- /examples/atomic/test.php: -------------------------------------------------------------------------------- 1 | add(12)."\n"; 4 | echo $atomic->sub(11)."\n"; 5 | echo $atomic->cmpset(122, 999)."\n"; 6 | echo $atomic->cmpset(124, 999)."\n"; 7 | echo $atomic->get()."\n"; 8 | -------------------------------------------------------------------------------- /examples/coroutine/deadlock.php: -------------------------------------------------------------------------------- 1 | lock(); 8 | Co::sleep(1); 9 | $lock->unlock(); 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /examples/ssl/co_client.php: -------------------------------------------------------------------------------- 1 | set(['ssl_host_name' => 'pro-api.coinmarketcap.com']); 5 | $c->get('/'); 6 | var_dump($c->body, $c->headers); 7 | }); 8 | -------------------------------------------------------------------------------- /examples/timer/enable_coroutine.php: -------------------------------------------------------------------------------- 1 | false 4 | ]); 5 | Swoole\Timer::tick(1000, function () { 6 | $uid = Co::getuid(); 7 | assert($uid === -1); 8 | echo "#{$uid}\n"; 9 | }); 10 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_tracer.stub.php: -------------------------------------------------------------------------------- 1 | 'hello', 'uid' => 1991]); 4 | fwrite($fp, pack('N', strlen($msg)) . $msg); 5 | sleep(1); 6 | -------------------------------------------------------------------------------- /tests/swoole_global/closed_stdout.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_global: handle closed STDOUT/STDERR without exception 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 9 | --EXPECT-- 10 | -------------------------------------------------------------------------------- /tests/swoole_runtime/sockets/basic/ipv6_skipif.inc: -------------------------------------------------------------------------------- 1 | get()."\n"; 4 | echo $l->add(20)."\n"; 5 | echo $l->sub(20)."\n"; 6 | echo $l->sub(-20)."\n"; 7 | echo $l->cmpset(-2 ** 36, 0)."\n"; 8 | echo $l->cmpset(-2 ** 36 + 20, 0)."\n"; 9 | -------------------------------------------------------------------------------- /examples/http/redirect.php: -------------------------------------------------------------------------------- 1 | on('request', function ($req, Swoole\Http\Response $resp) { 5 | $resp->redirect("http://www.baidu.com/", 301); 6 | }); 7 | 8 | $http->start(); 9 | -------------------------------------------------------------------------------- /examples/coroutine/fread.php: -------------------------------------------------------------------------------- 1 | 1024*1024*4]); 5 | 6 | co::create(function () { 7 | var_dump(co::stats()); 8 | echo "no coro exit\n"; 9 | }); 10 | echo "exec file end\n"; 11 | -------------------------------------------------------------------------------- /examples/coroutine/redis/auth.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 6379); 5 | $redis->auth('root'); 6 | $redis->set('key', 'swoole redis work'); 7 | var_dump($redis->get('key')); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/udp/client.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 9905); 4 | $client->send(serialize(['hello' => str_repeat('A', 600), 'rand' => rand(1, 100)])); 5 | echo $client->recv() . "\n"; 6 | sleep(1); 7 | -------------------------------------------------------------------------------- /examples/coroutine/coro_sleep.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 9502); 4 | 5 | for ($i = 0; $i < 100; $i++) 6 | { 7 | $client->send("admin"); 8 | echo $client->recv()."\n"; 9 | sleep(1); 10 | } 11 | -------------------------------------------------------------------------------- /examples/coroutine/behavior/goto.php: -------------------------------------------------------------------------------- 1 | connect("127.0.0.1", 6379)); 5 | var_dump($redis->get("key")); 6 | var_dump($redis->set("key_22", str_repeat('A', 8192*256))); 7 | var_dump($redis->mget(["key", "key_22"])); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/server/single.php: -------------------------------------------------------------------------------- 1 | on('Receive', function($serv, $fd, $reactor_id, $data) { 6 | $serv->send($fd, "Swoole: $data"); 7 | }); 8 | 9 | $server->start(); 10 | -------------------------------------------------------------------------------- /tests/include/api/swoole_http_server/simple_http_server.php: -------------------------------------------------------------------------------- 1 | start(); -------------------------------------------------------------------------------- /examples/coroutine/redis/pub.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 6379); 6 | while (true) 7 | { 8 | $msg = $redis->publish('msg_1', 'hello-' . $i++); 9 | var_dump($msg); 10 | co::sleep(1); 11 | } 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /examples/timer/clear.php: -------------------------------------------------------------------------------- 1 | 0) 5 | { 6 | echo "master start\n"; 7 | $n->wait(1.5); 8 | echo "master end\n"; 9 | } 10 | else 11 | { 12 | echo "child start\n"; 13 | sleep(1); 14 | $n->wakeup(); 15 | echo "child end\n"; 16 | } 17 | -------------------------------------------------------------------------------- /examples/process/alarm.php: -------------------------------------------------------------------------------- 1 | 20) 8 | { 9 | Swoole\Process::alarm(-1); 10 | } 11 | }); 12 | 13 | Swoole\Process::alarm(100 * 1000); 14 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_coroutine_lock.stub.php: -------------------------------------------------------------------------------- 1 | 'hello', 'uid' => 1991]); 4 | fwrite($fp, pack('N', strlen($msg)) . $msg); 5 | sleep(1); 6 | var_dump(fread($fp, 8192)); 7 | fclose($fp); 8 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_lock.stub.php: -------------------------------------------------------------------------------- 1 | $v){ 7 | echo $v."\n"; 8 | } 9 | }); 10 | 11 | go(function () { 12 | echo "222222\n"; 13 | }); 14 | echo "end\n"; 15 | -------------------------------------------------------------------------------- /examples/coroutine/redis/serialize.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 6379, true); // param3 is serialize 6 | $redis->set('foo', ['bar' => 'baz']); 7 | $ret = $redis->get('foo'); 8 | var_dump($ret); 9 | }); 10 | -------------------------------------------------------------------------------- /tests/include/api/swoole_thread/putenv.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | 11 | --EXPECT-- 12 | -------------------------------------------------------------------------------- /examples/coroutine/exit_with_status.php: -------------------------------------------------------------------------------- 1 | getStatus(); 9 | } 10 | }); 11 | Swoole\Event::wait(); 12 | exit($exit_status); 13 | -------------------------------------------------------------------------------- /tests/include/ssl_certs/client.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCRFJwc1004slJg28oZEKEP8h9c 3 | 057iJOTHoNQadH6dZeJMIos3T22ZJOGJE0/x13UxOvNtgqoaPgsBhFalmcsndgGZ 4 | o/Ozhm+GUQsshc843xMHQk78qmUlAaHNYL0hnRImgOJlxPO2NF3DAQWrDq35ju+p 5 | 7s8mly0+8Q46wfkMOQIDAQAB 6 | -----END PUBLIC KEY----- 7 | -------------------------------------------------------------------------------- /tests/include/ssl_certs/server.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCoOKDcu5YkjVFNU4GUBBCjydc5 3 | zYGws2xCf0JbCoSzMyI4r/sWk72BX31HGcPvjcLAsEFGLHQLJg8EE+MHU6+iQSsG 4 | LikZ8i/5eTf4eFRJjYdjBs9jUqqOukDToiTDmIZrsZnK9PFlz6+h6QPiraUIDbdj 5 | RQdJ0m2/xL8iYEsfOQIDAQAB 6 | -----END PUBLIC KEY----- 7 | -------------------------------------------------------------------------------- /examples/php/stream_client.php: -------------------------------------------------------------------------------- 1 | \n"; 5 | } else { 6 | fwrite($fp, "GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n"); 7 | sleep(1000); 8 | fclose($fp); 9 | } 10 | -------------------------------------------------------------------------------- /examples/process/msgqueue_client.php: -------------------------------------------------------------------------------- 1 | stats()); 8 | } 9 | elseif ($i % 300 == 299) 10 | { 11 | sleep(1); 12 | } 13 | $mq->push("hello $i"); 14 | } 15 | -------------------------------------------------------------------------------- /examples/thread/run_test.php: -------------------------------------------------------------------------------- 1 | join(); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /examples/coroutine/sleep.php: -------------------------------------------------------------------------------- 1 | set([ 5 | 'worker_num' => 1, 6 | ]); 7 | 8 | $server->on('Request', function ($request, $response) { 9 | Swoole\Coroutine::sleep(0.2); 10 | $response->end('Test End'); 11 | }); 12 | 13 | $server->start(); 14 | -------------------------------------------------------------------------------- /examples/event/cycle.php: -------------------------------------------------------------------------------- 1 | struct make_void 8 | { 9 | using type = void; 10 | }; 11 | template using void_t = typename make_void::type; 12 | } // namespace detail 13 | } // namespace nlohmann 14 | -------------------------------------------------------------------------------- /examples/ipv6/udp_client.php: -------------------------------------------------------------------------------- 1 | connect('::1', 9502); 4 | $client->send("admin"); 5 | echo $client->recv()."\n"; 6 | var_dump($client->getsockname()); 7 | var_dump($client->getpeername()); 8 | $client->sendto('::1', 9502, "admin2"); 9 | echo $client->recv()."\n"; 10 | sleep(1); 11 | -------------------------------------------------------------------------------- /examples/thread/test.php: -------------------------------------------------------------------------------- 1 | uuid = uniqid(); 11 | $map['obj'] = $o; 12 | 13 | var_dump($map['obj']); 14 | 15 | $s = serialize($map); 16 | var_dump(unserialize($s)); 17 | 18 | -------------------------------------------------------------------------------- /tests/swoole_client_async/connect_twice.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_client_async: connect twice 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 10 | --EXPECT-- 11 | error 12 | -------------------------------------------------------------------------------- /tests/swoole_function/swoole_cpu_num.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_function: swoole_cpu_num 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 13 | --EXPECTF-- 14 | cpu_num: %d 15 | -------------------------------------------------------------------------------- /tests/swoole_global/function_alias.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_global: function alias 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 12 | --EXPECTF-- 13 | bool(true) 14 | -------------------------------------------------------------------------------- /examples/http/raw.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | 14 | --EXPECT-- 15 | OK 16 | -------------------------------------------------------------------------------- /tests/swoole_timer/swoole_timer_list_alias.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_timer: function alias about swoole_timer_list 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 10 | --EXPECT-- 11 | 3 12 | -------------------------------------------------------------------------------- /examples/process/daemon.php: -------------------------------------------------------------------------------- 1 | connect(__DIR__ . '/svr.sock', 0, -1)) 4 | { 5 | exit("connect failed. Error: {$client->errCode}\n"); 6 | } 7 | 8 | $client->send("hello world\n"); 9 | echo $client->recv(); 10 | $client->close(); 11 | 12 | sleep(1); 13 | -------------------------------------------------------------------------------- /examples/unixsock/stream_client.php: -------------------------------------------------------------------------------- 1 | connect(__DIR__.'/svr.sock', 0, -1)) 4 | { 5 | exit("connect failed. Error: {$client->errCode}\n"); 6 | } 7 | 8 | $client->send("hello world\n"); 9 | echo $client->recv(); 10 | $client->close(); 11 | 12 | sleep(1); 13 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_redis_server.stub.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | 11 | --EXPECTF-- 12 | %d 13 | -------------------------------------------------------------------------------- /tests/swoole_function/swoole_version.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_function: swoole_version 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 13 | --EXPECTF-- 14 | swoole_version: %s 15 | -------------------------------------------------------------------------------- /examples/process/pool_socket.php: -------------------------------------------------------------------------------- 1 | on("Message", function ($pool, $message) { 5 | echo "Message: {$message}\n"; 6 | $pool->write("hello "); 7 | $pool->write("world "); 8 | $pool->write("\n"); 9 | }); 10 | 11 | $pool->listen('127.0.0.1', 8089); 12 | 13 | $pool->start(); 14 | -------------------------------------------------------------------------------- /examples/coroutine/stack.php: -------------------------------------------------------------------------------- 1 | 8192*4]); 3 | 4 | function test($n) 5 | { 6 | $a = 1; 7 | $b = 2; 8 | $c = 3; 9 | $d = 4; 10 | static $i; 11 | 12 | usleep(100000); 13 | echo "index=".($i++)."\n"; 14 | 15 | return test($n + $a + $b + $c + $d); 16 | } 17 | 18 | go(function () { 19 | test(9); 20 | }); 21 | -------------------------------------------------------------------------------- /scripts/code-stats.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | __CURRENT__=$(pwd) 3 | __DIR__=$(cd "$(dirname "$0")";pwd) 4 | 5 | # enter the dir 6 | cd "${__DIR__}/.." 7 | cloc . --exclude-dir=thirdparty,Debug,CMakeFiles,build,.git \ 8 | --fullpath \ 9 | --not-match-d='tools/vendor' \ 10 | --not-match-d='tests/include/lib/vendor' \ 11 | --not-match-f='ext-src/php_swoole_library\.h$' 12 | -------------------------------------------------------------------------------- /tests/swoole_global/unset_property_03.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_global: unset user class's own property 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | t); 14 | ?> 15 | --EXPECTF-- 16 | -------------------------------------------------------------------------------- /tests/swoole_table/create_10k_object.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_table: create 10,000 objects 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 13 | --EXPECT-- 14 | DONE 15 | -------------------------------------------------------------------------------- /tests/include/api/swoole_http_server/http_server_without_response.php: -------------------------------------------------------------------------------- 1 | on("request", function ($request, $response) { 8 | }); 9 | 10 | $httpServer->start(); 11 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/empty.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: coro empty 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 14 | --EXPECT-- 15 | co[1] start 16 | co[1] exit 17 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/exit_84.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: exit 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 12 | --EXPECTF-- 13 | int(1) 14 | string(4) "exit" 15 | int(0) 16 | -------------------------------------------------------------------------------- /tests/swoole_runtime/get_hook_flags.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_runtime: get hook flags 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 14 | --EXPECT-- 15 | -------------------------------------------------------------------------------- /tests/swoole_thread/empty_args.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_thread: info 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 17 | --EXPECTF-- 18 | -------------------------------------------------------------------------------- /tools/gen-data.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | start(); 4 | 5 | function pyhon_process(Swoole\Process $worker) 6 | { 7 | $worker->exec('/usr/bin/python', array("echo.py")); 8 | } 9 | 10 | $process->write("hello world\n"); 11 | echo $process->read(); 12 | 13 | $ret = Swoole\Process::wait(); 14 | var_dump($ret); 15 | -------------------------------------------------------------------------------- /tests/swoole_runtime/sockets/basic/mcast_helpers.php.inc: -------------------------------------------------------------------------------- 1 | 7 | --FILE-- 8 | 16 | --EXPECT-- 17 | -------------------------------------------------------------------------------- /examples/client/test.txt: -------------------------------------------------------------------------------- 1 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx 2 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx 3 | XXXXXXXXXXXXXXXXXXXXXXx 4 | XXXXXXXXXXXXXXXXXXXXX 5 | XXXXXXXXXXXXXXXXXXXXXXX 6 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 7 | BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 8 | TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 9 | DDDDDDDDDDDDDDDDDDDDDDDDDDD 10 | -------------------------------------------------------------------------------- /examples/coroutine/cancel_throw.php: -------------------------------------------------------------------------------- 1 | listen("127.0.0.1", $port, SWOOLE_SOCK_TCP); 7 | } 8 | 9 | $serv->on("receive", function($serv, $fd, $reactor_id, $data) { 10 | $info = $serv->getClientInfo($fd); 11 | var_dump($info); 12 | }); 13 | 14 | $serv->start(); 15 | -------------------------------------------------------------------------------- /tests/swoole_coroutine_system/sleep.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine_system: sleep 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 15 | --EXPECT-- 16 | OK 17 | -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_connect_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ftp_connect - return FALSE if connection fails and Waning is generated 3 | --FILE-- 4 | 10 | --EXPECTF-- 11 | Warning: ftp_connect(): getaddrinfo for 'dummy-host-name' failed, error: %s in %s on line %d 12 | bool(false) 13 | -------------------------------------------------------------------------------- /examples/coroutine/behavior/do-while.php: -------------------------------------------------------------------------------- 1 | 2000, 4 | 'death_loop_threshold' => 5, 5 | ]); 6 | echo "start\n"; 7 | go(function () { 8 | echo "coro start\n"; 9 | do{ 10 | echo "111\n"; 11 | sleep(1); 12 | } while(1); 13 | }); 14 | 15 | go(function () { 16 | echo "222222\n"; 17 | }); 18 | echo "end\n"; 19 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/bug_5699.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: Github bug #5699 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 15 | --EXPECT-- 16 | -------------------------------------------------------------------------------- /tests/swoole_event/defer_without_io.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_event: Swoole\Event::defer without io 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 15 | --EXPECT-- 16 | defer [1] 17 | -------------------------------------------------------------------------------- /tests/swoole_event/simple.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_event: Swoole\Event::exit 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 7 | 16 | --EXPECT-- 17 | tick 18 | -------------------------------------------------------------------------------- /tests/swoole_process/ctor.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: ctor 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 16 | --EXPECT-- 17 | SUCCESS 18 | -------------------------------------------------------------------------------- /examples/coroutine/timer_test.php: -------------------------------------------------------------------------------- 1 | 17 | -------------------------------------------------------------------------------- /examples/php/inotify.php: -------------------------------------------------------------------------------- 1 | join(); 13 | } 14 | } else { 15 | var_dump($args[0], $args[1], $args[2]); 16 | sleep(1); 17 | } 18 | -------------------------------------------------------------------------------- /examples/dtls/client.php: -------------------------------------------------------------------------------- 1 | connect("127.0.0.1", 9905); 8 | echo "connect OK\n"; 9 | $client->send("hello world"); 10 | echo $client->recv(); 11 | $client->close(); 12 | echo "END\n"; 13 | } 14 | ); -------------------------------------------------------------------------------- /examples/tracer/co.php: -------------------------------------------------------------------------------- 1 | __DIR__]); 3 | 4 | function sleep_n($time) 5 | { 6 | Co::sleep($time); 7 | } 8 | 9 | Co\run(function () { 10 | Co\go(function () { 11 | sleep_n(0.1); 12 | }); 13 | 14 | Co\go(function () { 15 | sleep_n(0.2); 16 | }); 17 | 18 | sleep_n(0.3); 19 | }); 20 | 21 | swoole_tracer_prof_end('./test.json'); -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_thread_queue.stub.php: -------------------------------------------------------------------------------- 1 | connect('::1', 9501, -1)) 4 | { 5 | exit("connect failed. Error: {$client->errCode}\n"); 6 | } 7 | 8 | var_dump($client->getsockname()); 9 | 10 | for($i=0; $i < 1; $i ++) 11 | { 12 | $client->send("hello world\n"); 13 | echo $client->recv(); 14 | usleep(2000); 15 | } 16 | 17 | $client->close(); 18 | -------------------------------------------------------------------------------- /tests/swoole_thread/fatal_error_2.inc: -------------------------------------------------------------------------------- 1 | join(); 10 | echo "stop child thread\n"; 11 | } else { 12 | (function () { 13 | swoole_implicit_fn('fatal_error'); 14 | })(); 15 | } 16 | echo "DONE\n"; 17 | -------------------------------------------------------------------------------- /examples/coroutine/coro_nested_empty.php: -------------------------------------------------------------------------------- 1 | getMessage(), "\n"; 10 | } finally { 11 | echo "First finally.\n"; 12 | } 13 | }); 14 | echo "exec file end\n"; 15 | -------------------------------------------------------------------------------- /examples/coroutine/util/resume001.php: -------------------------------------------------------------------------------- 1 | set(['worker_num' => 8, ]); 5 | 6 | $http->on("start", function ($server) { 7 | echo "Swoole http server is started at http://127.0.0.1:9501\n"; 8 | }); 9 | 10 | $http->on("request", function ($request, $response) { 11 | sleep(1); 12 | $response->end("Hello World\n"); 13 | }); 14 | 15 | $http->start(); 16 | -------------------------------------------------------------------------------- /examples/tracer/gc.php: -------------------------------------------------------------------------------- 1 | pro = $obj; 16 | unset($obj); 17 | 18 | swoole_tracer_leak_detect(64); 19 | } 20 | var_dump(memory_get_usage()); 21 | } 22 | foo(); 23 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/cid.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: cid increment 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 15 | --EXPECT-- 16 | DONE 17 | -------------------------------------------------------------------------------- /tests/swoole_coroutine_system/readfile.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine_system: readFile 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 14 | --EXPECT-- 15 | -------------------------------------------------------------------------------- /tests/swoole_server_coro/random_port.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_server_coro: bind random port 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | port > 0 and $server->port < 65535); 12 | }); 13 | 14 | ?> 15 | --EXPECT-- 16 | -------------------------------------------------------------------------------- /tests/swoole_ssh2/ssh2_auth.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ssh2_auth_FOO() - Attempt to authenticate to a remote host 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | 14 | --EXPECT-- 15 | bool(true) 16 | -------------------------------------------------------------------------------- /examples/coroutine/mysql_escape.php: -------------------------------------------------------------------------------- 1 | connect([ 7 | 'host' => '127.0.0.1', 8 | 'port' => 3306, 9 | 'user' => 'root', 10 | 'password' => 'root', 11 | 'database' => 'test', 12 | ]); 13 | $res = $swoole_mysql->escape(""); 14 | var_dump($res); 15 | }); 16 | 17 | -------------------------------------------------------------------------------- /examples/thread/lock.php: -------------------------------------------------------------------------------- 1 | lock(); 11 | $thread = new Thread(__FILE__, $lock); 12 | $lock->lock(); 13 | echo "main thread\n"; 14 | $thread->join(); 15 | } else { 16 | $lock = $args[0]; 17 | sleep(1); 18 | $lock->unlock(); 19 | } 20 | -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_constructor.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Attempt to instantiate an FTP\Connection directly 3 | --FILE-- 4 | getMessage(), "\n"; 10 | } 11 | }); 12 | ?> 13 | --EXPECT-- 14 | Exception: Cannot directly construct FTP\Connection, use ftp_connect() or ftp_ssl_connect() instead -------------------------------------------------------------------------------- /examples/process/select.php: -------------------------------------------------------------------------------- 1 | pid . "\n"; 5 | sleep(2); 6 | $worker->write("hello master\n"); 7 | $worker->exit(0); 8 | }, false); 9 | 10 | $pid = $process->start(); 11 | $r = array($process); 12 | $ret = swoole_select($r, null, null, 1.0); 13 | var_dump($ret); 14 | var_dump($process->read()); 15 | -------------------------------------------------------------------------------- /tests/swoole_runtime/out_of_coroutine.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_runtime: out of coroutine 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 16 | --EXPECT-- 17 | -------------------------------------------------------------------------------- /tests/swoole_thread/server/functions.inc: -------------------------------------------------------------------------------- 1 | set([ 6 | 'open_eof_check' => true, 7 | 'package_eof' => "\r\n", 8 | ]); 9 | Assert::assert($cli->connect('127.0.0.1', $port, 2)); 10 | $cli->send(json_encode(['type' => 'eof']) . "\r\n"); 11 | Assert::eq($cli->recv(), "EOF\r\n"); 12 | } 13 | -------------------------------------------------------------------------------- /examples/client/long_tcp.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 9501)) 6 | { 7 | exit("connect failed\n"); 8 | } 9 | $client->send(str_repeat("A", 600)); 10 | $data = $client->recv(7000, 0); 11 | if($data === false) 12 | { 13 | echo "recv fail\n"; 14 | break; 15 | } 16 | var_dump($data); 17 | $client->close(); 18 | } 19 | -------------------------------------------------------------------------------- /examples/coroutine/coro_util.php: -------------------------------------------------------------------------------- 1 | 1, 'usec' => 500000); 11 | socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); 12 | 13 | $n = socket_recv($socket, $buf, 2048, MSG_WAITALL); 14 | 15 | var_dump($n, $buf); 16 | -------------------------------------------------------------------------------- /tests/swoole_http_server_coro/random_port.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_http_server_coro: bind random port 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | port > 0 and $server->port < 65535); 12 | }); 13 | 14 | ?> 15 | --EXPECT-- 16 | -------------------------------------------------------------------------------- /tests/swoole_library/database/pdo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_library/database: pdo 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 13 | --EXPECTF-- 14 | Use %fs for %d queries 15 | -------------------------------------------------------------------------------- /examples/coroutine/mysql_execute_empty.php: -------------------------------------------------------------------------------- 1 | '127.0.0.1', 6 | 'user' => 'root', 7 | 'password' => 'root', 8 | 'database' => 'test' 9 | ]; 10 | $db->connect($server); 11 | $stmt = $db->prepare('SELECT * FROM `userinfo`'); 12 | $ret = $stmt->execute(); 13 | var_dump($ret); 14 | }); 15 | -------------------------------------------------------------------------------- /scripts/rename.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | add(1); 10 | $wg->add(-1); 11 | $wg->wait(); 12 | $wg->add(1); 13 | $wg->done(); 14 | $wg->wait(); 15 | echo "DONE\n"; 16 | ?> 17 | --EXPECT-- 18 | DONE 19 | -------------------------------------------------------------------------------- /tests/swoole_curl/multi/no_hook.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_curl/multi: no hook 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 18 | --EXPECT-- 19 | Done 20 | -------------------------------------------------------------------------------- /tests/swoole_pdo_sqlite/pdo_sqlite.inc: -------------------------------------------------------------------------------- 1 | getMessage()); 11 | } 12 | } 13 | 14 | public static function create(): PDO 15 | { 16 | return new PDO(SQLITE_DSN); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/cpp/Makefile: -------------------------------------------------------------------------------- 1 | all: co repeat test_server 2 | 3 | co: co.cc 4 | g++ co.cc -I../.. -I../../include -DHAVE_CONFIG_H -L../../lib -lswoole -o co -g 5 | repeat: repeat.cc 6 | g++ repeat.cc -I../.. -I../../include -DHAVE_CONFIG_H -L../../lib -lswoole -o repeat -g 7 | test_server: test_server.cc 8 | g++ test_server.cc -I../.. -I../../include -DHAVE_CONFIG_H -L../../lib -lswoole -o test_server -g 9 | clean: 10 | rm -f co repeat test_server 11 | -------------------------------------------------------------------------------- /examples/http/static_handler.php: -------------------------------------------------------------------------------- 1 | set([ 5 | 'enable_static_handler' => true, 6 | 'http_autoindex' => true, 7 | 'document_root' => realpath(__DIR__.'/../www/'), 8 | ]); 9 | 10 | $http->on('request', function ($req, $resp) { 11 | $resp->end("hello world\n"); 12 | }); 13 | 14 | $http->start(); 15 | -------------------------------------------------------------------------------- /examples/runtime/sqlite.php: -------------------------------------------------------------------------------- 1 | SWOOLE_HOOK_PDO_SQLITE]); 6 | 7 | run(function() { 8 | $db = new PDO('sqlite::memory:'); 9 | for ($i = 0; $i < 10; $i++) { 10 | go(function() use($i, $db) { 11 | $db->query('select randomblob(99999999)'); 12 | var_dump($i); 13 | }); 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /tests/swoole_library/database/mysqli.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_library/database: pdo 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 13 | --EXPECTF-- 14 | Use %fs for %d queries 15 | -------------------------------------------------------------------------------- /tests/swoole_library/database/redis.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_library/database: pdo 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 13 | --EXPECTF-- 14 | Use %fs for %d queries 15 | -------------------------------------------------------------------------------- /tests/swoole_process/pop.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: pop 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | useQueue(); 12 | $proc->push("SUCCESS"); 13 | echo $proc->pop(); 14 | $proc->freeQueue(); 15 | ?> 16 | --EXPECT-- 17 | SUCCESS 18 | -------------------------------------------------------------------------------- /tests/swoole_process/start.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: start 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | start(); 13 | Assert::assert($r > 0); 14 | $proc->close(); 15 | 16 | \Swoole\Process::wait(true); 17 | ?> 18 | --EXPECT-- 19 | SUCCESS 20 | -------------------------------------------------------------------------------- /tests/swoole_timer/enable_coroutine.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_timer: enable_coroutine setting 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | false 10 | ]); 11 | Swoole\Timer::after(1, function () { 12 | $uid = Co::getuid(); 13 | echo "#{$uid}\n"; 14 | }); 15 | ?> 16 | --EXPECT-- 17 | #-1 18 | -------------------------------------------------------------------------------- /tests/template: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | {{test_name}}: {{test_intro}} 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | parentFunc = function () use ($pm) { 10 | 11 | }; 12 | $pm->childFunc = function () use ($pm) { 13 | 14 | }; 15 | $pm->childFirst(); 16 | $pm->run(); 17 | ?> 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_coroutine_scheduler.stub.php: -------------------------------------------------------------------------------- 1 | 7 | --FILE-- 8 | connect('www.qq.com', 80)); 14 | }); 15 | 16 | ?> 17 | --EXPECT-- 18 | -------------------------------------------------------------------------------- /tests/swoole_function/swoole_get_local_mac.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_function: get mac address 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 16 | --EXPECT-- 17 | -------------------------------------------------------------------------------- /examples/coroutine/http/write_func.php: -------------------------------------------------------------------------------- 1 | SWOOLE_TRACE_HTTP2, 4 | 'log_level' => 0, 5 | ]); 6 | Co\run(function () { 7 | $client = new Swoole\Coroutine\Http\Client('www.jd.com', 443, true); 8 | $client->set(['write_func' => function($client, $data) { 9 | var_dump(strlen($data)); 10 | }]); 11 | $client->get('/'); 12 | var_dump(strlen($client->getBody())); 13 | return 0; 14 | }); 15 | -------------------------------------------------------------------------------- /tests/swoole_lock/lock_nb.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_lock: lock nb 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | lock()); 11 | 12 | $ret = $lock->lock(LOCK_EX | LOCK_NB); 13 | Assert::false($ret); 14 | 15 | $lock->unlock(); 16 | Assert::true($lock->lock(LOCK_EX | LOCK_NB)); 17 | ?> 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /tests/swoole_ssh2/testkey_ed25519: -------------------------------------------------------------------------------- 1 | -----BEGIN OPENSSH PRIVATE KEY----- 2 | b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW 3 | QyNTUxOQAAACB0GwDRjBT3NEK1LE48T+ElF6oFvHmJntQ5cZQHBVlDAgAAAJhU66/nVOuv 4 | 5wAAAAtzc2gtZWQyNTUxOQAAACB0GwDRjBT3NEK1LE48T+ElF6oFvHmJntQ5cZQHBVlDAg 5 | AAAEC9tmUV4e++pQWWQm3ffFvGZZYPiZkD+UqrZYfghuLAeXQbANGMFPc0QrUsTjxP4SUX 6 | qgW8eYme1DlxlAcFWUMCAAAAEHJhbmdvQHN3b29sZS5jb20BAgMEBQ== 7 | -----END OPENSSH PRIVATE KEY----- 8 | -------------------------------------------------------------------------------- /tools/show-big-files.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 'unix:/tmp/mysql.sock', 7 | 'user' => 'root', 8 | 'password' => 'root', 9 | 'database' => 'test' 10 | ]; 11 | $db->connect($server); 12 | $stmt = $db->prepare('SELECT * FROM `user` WHERE id=?'); 13 | $ret = $stmt->execute([1]); 14 | var_dump($ret); 15 | }); 16 | -------------------------------------------------------------------------------- /examples/coroutine/redis_subscribe.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 6379); 8 | while (true) 9 | { 10 | $val = $redis->subscribe(['test']); 11 | //订阅的channel,以第一次调用subscribe时的channel为准,后续的subscribe调用是为了收取Redis Server的回包 12 | //如果需要改变订阅的channel,请close掉连接,再调用subscribe 13 | var_dump($val); 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /examples/server/dispatch_stream.php: -------------------------------------------------------------------------------- 1 | set(array( 5 | 'dispatch_mode' => 7, 6 | 'worker_num' => 2, 7 | )); 8 | 9 | $serv->on('receive', function (Swoole\Server $serv, $fd, $threadId, $data) 10 | { 11 | var_dump($data); 12 | echo "#{$serv->worker_id}>> received length=" . strlen($data) . "\n"; 13 | $serv->send($fd, "Swoole $data\n"); 14 | }); 15 | 16 | $serv->start(); 17 | -------------------------------------------------------------------------------- /tests/swoole_function/swoole_get_local_ip.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_function: get local ip 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 16 | --EXPECT-- 17 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_thread_barrier_arginfo.h: -------------------------------------------------------------------------------- 1 | /* This is a generated file, edit the .stub.php file instead. 2 | * Stub hash: 1fe9f55b0b9487e9cd469dcd215acee893254a04 */ 3 | 4 | ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Swoole_Thread_Barrier___construct, 0, 0, 1) 5 | ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0) 6 | ZEND_END_ARG_INFO() 7 | 8 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_Barrier_wait, 0, 0, IS_VOID, 0) 9 | ZEND_END_ARG_INFO() 10 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/dnslookup_5.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: async dns lookup [5] 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /tests/swoole_runtime/file_hook/include.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_runtime/file_hook: include 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 19 | --EXPECT-- 20 | A 21 | B 22 | -------------------------------------------------------------------------------- /examples/process/exec.php: -------------------------------------------------------------------------------- 1 | start(); 4 | 5 | function callback_function(Swoole\Process $worker) 6 | { 7 | $worker->exec('/usr/local/bin/php', array(__DIR__.'/stdin_stdout.php')); 8 | } 9 | 10 | echo "From Worker: ".$process->read(); 11 | $process->write("hello worker\n"); 12 | echo "From Worker: ".$process->read(); 13 | 14 | $ret = Swoole\Process::wait(); 15 | var_dump($ret); 16 | -------------------------------------------------------------------------------- /examples/thread/map.php: -------------------------------------------------------------------------------- 1 | random_int(1, 999999999999999999), 8 | 'b' => random_bytes(128), 9 | 'c' => uniqid(), 10 | 'd' => time(), 11 | ]; 12 | 13 | $map = new Thread\Map($array); 14 | $thread = new Thread(__FILE__, $map); 15 | } else { 16 | $map = $args[0]; 17 | var_dump($map->toArray()); 18 | } 19 | -------------------------------------------------------------------------------- /tests/swoole_channel_coro/pop_timeout1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_channel_coro: pop timeout 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | pop(1); 13 | echo "pop ret:".var_export($ret,1)." error:".$c1->errCode."\n"; 14 | 15 | }); 16 | ?> 17 | --EXPECTF-- 18 | pop ret:false error:-1 19 | -------------------------------------------------------------------------------- /tests/swoole_coroutine_system/gethostbyname.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine_system: gethostbyname 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 17 | --EXPECT-- 18 | -------------------------------------------------------------------------------- /tests/swoole_thread/fatal_error_1.inc: -------------------------------------------------------------------------------- 1 | join(); 10 | echo "stop child thread\n"; 11 | } else { 12 | Co\run(function () { 13 | (function () { 14 | swoole_implicit_fn('fatal_error'); 15 | })(); 16 | }); 17 | } 18 | echo "DONE\n"; 19 | -------------------------------------------------------------------------------- /examples/udp/server.php: -------------------------------------------------------------------------------- 1 | listen('0.0.0.0', 9906 + $i, SWOOLE_SOCK_UDP); 6 | } 7 | $server->set(['worker_num' => 4]); 8 | 9 | $server->on('Packet', function (Swoole\Server $serv, $data, $addr) 10 | { 11 | $serv->sendto($addr['address'], $addr['port'], "Swoole: $data", $addr['server_socket']); 12 | }); 13 | 14 | $server->start(); 15 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_http_request.stub.php: -------------------------------------------------------------------------------- 1 | 17 | --EXPECT-- 18 | bool(true) -------------------------------------------------------------------------------- /tests/swoole_process/freeQueue.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: freeQueue 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | useQueue(); 11 | Assert::assert($r); 12 | 13 | $proc->start(); 14 | $r = $proc->freeQueue(); 15 | Assert::assert($r); 16 | 17 | \Swoole\Process::wait(); 18 | 19 | ?> 20 | --EXPECT-- 21 | -------------------------------------------------------------------------------- /examples/coroutine/pdo/pdo_persistent.phpt: -------------------------------------------------------------------------------- 1 | true) 7 | ); 8 | echo "connected\n"; 9 | sleep(30); 10 | echo "sleep 30\n"; 11 | $pdo->exec("SELECT sleep(1)"); 12 | }); 13 | 14 | echo "DONE\n"; 15 | -------------------------------------------------------------------------------- /examples/coroutine/socket/sendto.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 9601); 7 | echo "connect ret:".var_export($ret,1)." error:".var_export($conn->errCode,1)."\n"; 8 | $ret = $conn->send(json_encode(['data' => 'hello'])); 9 | echo "send ret:".var_export($ret,1)."\n"; 10 | echo $conn->recv(); 11 | }); 12 | echo "end \n"; 13 | -------------------------------------------------------------------------------- /tests/swoole_channel_coro/pop_close1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_channel_coro: pop close 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | close(); 11 | 12 | go(function () use ($c1) { 13 | $ret = $c1->pop(); 14 | echo "pop ret:".var_export($ret,1)." error:".$c1->errCode."\n"; 15 | }); 16 | ?> 17 | --EXPECTF-- 18 | pop ret:false error:-2 19 | -------------------------------------------------------------------------------- /tests/swoole_ftp/bug27809.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #27809 (ftp_systype returns null) 3 | --FILE-- 4 | 16 | --EXPECT-- 17 | bool(true) 18 | string(6) "OS/400" 19 | -------------------------------------------------------------------------------- /tests/swoole_pdo_firebird/pdo_firebird.inc: -------------------------------------------------------------------------------- 1 | getMessage()); 11 | } 12 | } 13 | 14 | public static function create(): PDO 15 | { 16 | return new PDO(FIREBIRD_DSN, FIREBIRD_USER, FIREBIRD_PASSWORD); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/swoole_process/exit.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: exit 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | exit(9); 11 | }); 12 | $pid = $proc->start(); 13 | 14 | $i = \Swoole\Process::wait(true); 15 | Assert::same($i["code"], 9); 16 | 17 | echo "SUCCESS"; 18 | ?> 19 | --EXPECT-- 20 | SUCCESS 21 | -------------------------------------------------------------------------------- /tests/swoole_server/ssl/code/client.js: -------------------------------------------------------------------------------- 1 | const tls = require('tls'); 2 | 3 | const options = { 4 | rejectUnauthorized: false, 5 | }; 6 | 7 | var socket = tls.connect(process.argv[2], '127.0.0.1', options, () => { 8 | socket.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n'); 9 | }); 10 | 11 | socket.setEncoding('utf8'); 12 | socket.on('data', (data) => { 13 | console.log(data); 14 | }); 15 | 16 | socket.on('end', () => { 17 | console.log('Ended') 18 | }); -------------------------------------------------------------------------------- /examples/process/msgqueue_pool.php: -------------------------------------------------------------------------------- 1 | on("Message", function ($pool, $message) { 5 | echo "Message: {$message}\n"; 6 | }); 7 | 8 | $pool->on("WorkerStart", function ($pool, $workerId) { 9 | echo "Worker#{$workerId} is started\n"; 10 | }); 11 | 12 | $pool->on("WorkerStop", function ($pool, $workerId) { 13 | echo "Worker#{$workerId} is stopped\n"; 14 | }); 15 | 16 | $pool->start(); 17 | -------------------------------------------------------------------------------- /examples/runtime/file.php: -------------------------------------------------------------------------------- 1 | \n"; 7 | } else { 8 | fwrite($fp, "GET / HTTP/1.0\r\nHost: www.baidu.com\r\nAccept: */*\r\n\r\n"); 9 | while (!feof($fp)) { 10 | echo fgets($fp, 1024); 11 | } 12 | fclose($fp); 13 | } 14 | }); 15 | -------------------------------------------------------------------------------- /tests/swoole_channel_coro/pop_timeout5.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_channel_coro: pop timeout hanging up 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | pop(); 15 | echo "pop ret:".var_export($ret,1)." error:".$c1->errCode."\n"; 16 | }); 17 | ?> 18 | --EXPECTF-- 19 | -------------------------------------------------------------------------------- /tests/swoole_channel_coro/push_close1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_channel_coro: push close 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | close(); 11 | 12 | go(function () use ($c1) { 13 | $ret = $c1->push(1); 14 | echo "push ret:".var_export($ret,1)." error:".$c1->errCode."\n"; 15 | }); 16 | ?> 17 | --EXPECTF-- 18 | push ret:false error:-2 19 | -------------------------------------------------------------------------------- /tests/swoole_process/redirect.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: redirect 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | start(); 14 | $r = $proc->read(); 15 | echo "READ: $r~"; 16 | 17 | \Swoole\Process::wait(true); 18 | ?> 19 | --EXPECT-- 20 | READ: SUCCESS~ 21 | -------------------------------------------------------------------------------- /tests/swoole_runtime/unsafe/pcntl_fork.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_runtime/unsafe: pcntl_fork 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 17 | --EXPECTF-- 18 | Warning: pcntl_fork() has been disabled for security reasons in %s on line %d 19 | -------------------------------------------------------------------------------- /tests/swoole_stdext/string_method/1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_stdext/string_method: 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | parseStr(); 12 | Assert::eq($output['first'], 'value'); 13 | Assert::eq($output['arr'][0], 'foo bar'); 14 | Assert::eq($output['arr'][1], 'baz'); 15 | ?> 16 | --EXPECT-- 17 | -------------------------------------------------------------------------------- /tests/swoole_table/getMemorySize_1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_table: getMemorySize 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getMemorySize(), 0); 13 | $table->column('name', Table::TYPE_STRING, 32); 14 | $table->create(); 15 | Assert::greaterThan($table->getMemorySize(), 0); 16 | ?> 17 | --EXPECTF-- 18 | -------------------------------------------------------------------------------- /examples/thread/exit.php: -------------------------------------------------------------------------------- 1 | lock(); 11 | $thread = new Thread(__FILE__, $lock); 12 | echo "main thread\n"; 13 | $lock->unlock(); 14 | $thread->join(); 15 | var_dump($thread->getExitStatus()); 16 | } else { 17 | $lock = $args[0]; 18 | $lock->lock(); 19 | sleep(1); 20 | exit(234); 21 | } 22 | -------------------------------------------------------------------------------- /tests/include/lib/src/ThreadManager.php: -------------------------------------------------------------------------------- 1 | parentFunc)(); 16 | } else { 17 | ($this->childFunc)(...$args); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/swoole_process/null_callback.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: null callback 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | start(); 14 | 15 | ?> 16 | --EXPECTF-- 17 | Warning: Swoole\Process::start(): illegal callback function in %s 18 | -------------------------------------------------------------------------------- /tests/swoole_socket_coro/getsockname.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_socket_coro: getsockname 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | bind('127.0.0.1'); 10 | $info = $conn->getsockname(); 11 | Assert::same($info['address'] ?? '', '127.0.0.1'); 12 | Assert::greaterThan($info['port'], 0); 13 | ?> 14 | --EXPECT-- 15 | -------------------------------------------------------------------------------- /examples/coroutine/coro_call_user.php: -------------------------------------------------------------------------------- 1 | 1]); 4 | 5 | co::create(function() { 6 | echo "co func start\n"; 7 | $name = "call_user_func"; 8 | $ret = $name("test","test\n"); 9 | echo "co func end ret:{$ret}\n"; 10 | }); 11 | 12 | function test($params) 13 | { 14 | echo "func params:$params"; 15 | co::sleep(1); 16 | echo "func end\n"; 17 | return "test return\n"; 18 | } 19 | echo "main script last\n"; 20 | -------------------------------------------------------------------------------- /tests/swoole_client_sync/connect_2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_client_sync: connect 1 - 2 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(TEST_DOMAIN_3, 443); 13 | Assert::assert($r); 14 | $cli->close(); 15 | echo "SUCCESS"; 16 | ?> 17 | --EXPECT-- 18 | SUCCESS 19 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/create_after_rshutdown.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: create coroutine after RSHTUDOWN 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 18 | --EXPECTF-- 19 | DONE 20 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/dnslookup_query_hosts.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: dnslookup query hosts 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /tests/swoole_stdext/string_method/json.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_stdext/string_method: json 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | random_bytes(128)->base64Encode(), 'b' => random_int(1, PHP_INT_MAX), 'c' => php_uname()]; 10 | 11 | $str = $array->jsonEncode(); 12 | Assert::notEmpty($str); 13 | Assert::eq($str->jsonDecode(), $array); 14 | ?> 15 | --EXPECT-- 16 | -------------------------------------------------------------------------------- /tests/swoole_stdext/string_method/marshal.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_stdext/string_method: marshal 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | random_bytes(128)->base64Encode(), 'b' => random_int(1, PHP_INT_MAX), 'c' => php_uname()]; 10 | 11 | $str = $array->marshal(); 12 | Assert::notEmpty($str); 13 | Assert::eq($str->unmarshal(), $array); 14 | ?> 15 | --EXPECT-- 16 | -------------------------------------------------------------------------------- /examples/coroutine/redis/multi.php: -------------------------------------------------------------------------------- 1 | connect(REDIS_SERVER_HOST, REDIS_SERVER_PORT); 9 | $redis->multi(); 10 | $redis->set('key3', 'rango'); 11 | $redis->get('key1'); 12 | $redis->get('key2'); 13 | $redis->get('key3'); 14 | 15 | $result = $redis->exec(); 16 | var_dump($result); 17 | }); 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/coroutine/redis/pipeline.php: -------------------------------------------------------------------------------- 1 | connect(REDIS_SERVER_HOST, REDIS_SERVER_PORT); 9 | $redis->setDefer(); 10 | $redis->set('key1', 'value'); 11 | $redis->get('key1'); 12 | 13 | $result1 = $redis->recv(); 14 | $result2 = $redis->recv(); 15 | 16 | var_dump($result1, $result2); 17 | }); 18 | 19 | 20 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_channel_coro.stub.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | connect("11.11.11.11", 80, 0.5); 13 | Assert::false($r); 14 | Assert::eq($cli->errCode, SOCKET_ETIMEDOUT); 15 | ?> 16 | --EXPECT-- 17 | -------------------------------------------------------------------------------- /tests/swoole_global/unset_property_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_global: unset internal class property 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | capacity); 10 | ?> 11 | --EXPECTF-- 12 | Fatal error: Uncaught Error: Property capacity of class Swoole\Coroutine\Channel cannot be unset in %s/tests/%s/unset%s.php:%d 13 | Stack trace: 14 | #0 {main} 15 | thrown in %s 16 | -------------------------------------------------------------------------------- /tests/swoole_http2_client_coro/bug_5127.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_http2_client_coro: Github #5127 When use swoole in php 8.2,Swoole\Http2\Request may throw ErrorException:Creation of dynamic property $usePipelineRead 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | usePipelineRead = true; 11 | echo 'DONE'; 12 | ?> 13 | --EXPECT-- 14 | DONE 15 | -------------------------------------------------------------------------------- /tests/swoole_process/useQueue.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: useQueue 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | pop(); 11 | }); 12 | $proc->useQueue(); 13 | $proc->start(); 14 | $proc->push("SUCCESS"); 15 | 16 | \Swoole\Process::wait(true); 17 | $proc->freeQueue(); 18 | ?> 19 | --EXPECT-- 20 | SUCCESS 21 | -------------------------------------------------------------------------------- /tests/swoole_process_pool/shutdown.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process_pool: shutdown 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | on('workerStart', function (Swoole\Process\Pool $pool, int $workerId) 12 | { 13 | $pool->shutdown(); 14 | sleep(20); 15 | echo "ERROR\n"; 16 | }); 17 | 18 | $pool->start(); 19 | ?> 20 | --EXPECT-- 21 | -------------------------------------------------------------------------------- /examples/event/inotify.php: -------------------------------------------------------------------------------- 1 | set(array( 4 | 'worker_num' => 1, 5 | )); 6 | $serv->on('receive', function (Swoole\Server $serv, $fd, $reactor_id, $data) { 7 | echo "[#".posix_getpid()."]\tClient[$fd]: $data\n"; 8 | var_dump($serv->connection_info($fd, $reactor_id)); 9 | $serv->send($fd, json_encode(array("hello" => '1213', "bat" => "ab"))); 10 | //$serv->close($fd); 11 | }); 12 | $serv->start(); 13 | -------------------------------------------------------------------------------- /examples/process/client.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 8089, -1)) 5 | { 6 | exit("connect failed. Error: {$client->errCode}\n"); 7 | } 8 | 9 | function _send(Swoole\Client $client, $data) 10 | { 11 | return $client->send(pack('N', strlen($data)) . $data); 12 | } 13 | 14 | var_dump($client->getsockname()); 15 | 16 | 17 | _send($client, "hello world"); 18 | _send($client, "hello world [2]"); 19 | 20 | $client->close(); 21 | -------------------------------------------------------------------------------- /scripts/simple-compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | __CURRENT__=`pwd` 3 | __DIR__=$(cd "$(dirname "$0")";pwd) 4 | 5 | cd ${__DIR__} && cd ../ && \ 6 | ./clear.sh > /dev/null && \ 7 | phpize --clean > /dev/null && \ 8 | phpize > /dev/null && \ 9 | ./configure > /dev/null && \ 10 | make -j8 > /dev/null | tee /tmp/compile.log && \ 11 | (test "`cat /tmp/compile.log`"x = ""x || exit 255) && \ 12 | make install && \ 13 | echo "\n[swoole]\nextension=swoole.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini 14 | -------------------------------------------------------------------------------- /tests/swoole_client_async/enableSSL_bad_callback.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_client_async: enableSSL with bad callback 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | enableSSL(); 12 | } catch (Exception $e) { 13 | Assert::contains($e->getMessage(), 'require `onSslReady` callback'); 14 | } 15 | ?> 16 | --EXPECTF-- 17 | -------------------------------------------------------------------------------- /tests/swoole_coroutine_scheduler/getOptions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine_scheduler: getOptions 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | set(['max_coroutine' => 100, 'deadlock_check_max_stack' => 64, ]); 11 | $options = $sch->getOptions(); 12 | ASsert::isArray($options); 13 | Assert::eq($options['deadlock_check_max_stack'], 64); 14 | ?> 15 | --EXPECT-- 16 | -------------------------------------------------------------------------------- /tests/swoole_coroutine_util/fread.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine_util: fread 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /tests/swoole_process/kill.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: kill 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | start(); 13 | Swoole\Process::kill($pid, SIGKILL); 14 | $i = \Swoole\Process::wait(true); 15 | Assert::same($i["signal"], SIGKILL); 16 | echo "SUCCESS"; 17 | ?> 18 | --EXPECT-- 19 | SUCCESS 20 | -------------------------------------------------------------------------------- /tests/swoole_timer/greater_than_0.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_timer: Timer must be greater than 0 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 14 | --EXPECTF-- 15 | -------------------------------------------------------------------------------- /examples/coroutine/http_download.php: -------------------------------------------------------------------------------- 1 | set(['timeout' => -1]); 9 | $cli->setHeaders([ 10 | 'Host' => $host, 11 | "User-Agent" => 'Chrome/49.0.2587.3', 12 | 'Accept' => '*', 13 | 'Accept-Encoding' => 'gzip' 14 | ]); 15 | $cli->download('/dist/skin1/images/logo-white.png', '/tmp/logo.png'); 16 | }); 17 | -------------------------------------------------------------------------------- /examples/server/dispatch_func.php: -------------------------------------------------------------------------------- 1 | set(array( 5 | 'dispatch_func' => function ($serv, $fd, $type, $data) { 6 | var_dump($fd, $type, $data); 7 | return intval($data[0]); 8 | }, 9 | )); 10 | 11 | $serv->on('receive', function (Swoole\Server $serv, $fd, $threadId, $data) 12 | { 13 | var_dump($data); 14 | echo "#{$serv->worker_id}>> received length=" . strlen($data) . "\n"; 15 | }); 16 | 17 | $serv->start(); 18 | -------------------------------------------------------------------------------- /examples/thread/array.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | add(199), 200); 12 | Assert::same($atomic->sub(35), 165); 13 | Assert::same($atomic->get(), 165); 14 | Assert::assert($atomic->cmpset(165, 1)); 15 | Assert::assert(!$atomic->cmpset(1555, 0)); 16 | ?> 17 | --EXPECT-- 18 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/getElasped.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: getElapsed 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 17 | --EXPECT-- 18 | int(-1) 19 | int(-1) 20 | bool(true) 21 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/output/ob_main.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine/output: main output global 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /tests/swoole_process/process_id.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: Github bug #5825 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | id, $n); 13 | }); 14 | Assert::same($process->id, $n); 15 | $process->start(); 16 | } 17 | ?> 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /tests/swoole_server/listen_fail.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_server: listen fail 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SWOOLE_LOG_NONE]); 9 | try { 10 | $serv = new Swoole\Server('192.0.0.1', 80, SWOOLE_PROCESS); 11 | } catch (Swoole\Exception $e) { 12 | Assert::same($e->getCode(), SOCKET_EADDRNOTAVAIL); 13 | echo "DONE\n"; 14 | } 15 | ?> 16 | --EXPECT-- 17 | DONE 18 | -------------------------------------------------------------------------------- /tests/swoole_stdext/typed_array/0.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_stdext/typed_array: 0 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | '); 10 | 11 | try { 12 | $array = typed_array('getMessage()->contains("must start with '<' and end with '>'")); 15 | echo "DONE\n"; 16 | } 17 | ?> 18 | --EXPECT-- 19 | DONE 20 | -------------------------------------------------------------------------------- /examples/coroutine/exit_in_coroutine.php: -------------------------------------------------------------------------------- 1 | getStatus() === 1); 23 | assert($e->getFlags() === SWOOLE_EXIT_IN_COROUTINE); 24 | return; 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /examples/process/close.php: -------------------------------------------------------------------------------- 1 | pid . "\n"; 5 | sleep(2); 6 | $worker->close(Swoole\Process::PIPE_READ); 7 | $worker->write("hello master\n"); 8 | $worker->exit(0); 9 | }, false); 10 | 11 | $pid = $process->start(); 12 | $r = array($process); 13 | $w = array(); 14 | $e = array(); 15 | $ret = swoole_select($r, $w, $e, 1.0); 16 | var_dump($ret); 17 | var_dump($process->read()); 18 | -------------------------------------------------------------------------------- /tests/swoole_process/setaffinity.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: setAffinity 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 1) { 14 | $r = Swoole\Process::setaffinity([0, 1]); 15 | Assert::assert($r); 16 | } 17 | echo "SUCCESS"; 18 | ?> 19 | --EXPECT-- 20 | SUCCESS 21 | -------------------------------------------------------------------------------- /examples/coroutine/redis/sub.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 6379); 5 | $msg = $redis->subscribe(array("msg_1")); 6 | while ($msg = $redis->recv()) 7 | { 8 | var_dump($msg); 9 | } 10 | }); 11 | 12 | go(function () { 13 | $redis = new Swoole\Coroutine\Redis(); 14 | $redis->connect('127.0.0.1', 6379); 15 | $msg = $redis->subscribe(array("msg_2")); 16 | while ($msg = $redis->recv()) 17 | { 18 | var_dump($msg); 19 | } 20 | }); 21 | -------------------------------------------------------------------------------- /examples/coroutine/socket/accept.php: -------------------------------------------------------------------------------- 1 | bind('127.0.0.1', 9601); 5 | var_dump($ret); 6 | assert($sock->listen(512)); 7 | $conn = $sock->accept(); 8 | 9 | $data = $conn->recv(); 10 | var_dump($data); 11 | $json = json_decode($data, true); 12 | var_dump($json); 13 | $ret = $conn->send("world\n"); 14 | echo "send res {$ret} \n"; 15 | $conn->close(); 16 | }); 17 | -------------------------------------------------------------------------------- /examples/ssl/http_client.php: -------------------------------------------------------------------------------- 1 | setHeaders(array('User-Agent' => 'swoole-http-client')); 4 | 5 | $cli->on('close', function($_cli) { 6 | echo "connection is closed\n"; 7 | }); 8 | $cli->get('/?dump.php?corpid=ding880f44069a80bca1&corpsecret=YB1cT8FNeN7VCm3eThwDAncsmSl4Ajl_1DmckaOFmOZhTFzexLbIzq5ueH3YcHrx', function ($cli) { 9 | var_dump($cli); 10 | var_dump($cli->headers); 11 | echo $cli->body; 12 | //$cli->close(); 13 | }); 14 | -------------------------------------------------------------------------------- /tests/swoole_coroutine_system/gethostbyname_ipv6.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine_system: gethostbyname for IPv6 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /tests/swoole_process/exec.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: exec 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | exec("/usr/bin/printf", ["HELLO"]); 11 | }, true); 12 | $proc->start(); 13 | echo $proc->read(); 14 | $proc->exec("/usr/bin/printf", [" WORLD"]); 15 | 16 | \Swoole\Process::wait(true); 17 | ?> 18 | --EXPECT-- 19 | HELLO WORLD 20 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/current.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: current cid 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 19 | --EXPECT-- 20 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/dnslookup_3.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: async dns lookup [3] 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 16 | --EXPECT-- 17 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/output/create.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine/output: main output global 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 20 | --EXPECT-- 21 | 2 22 | 1 23 | 0 24 | -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_alloc_basic1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing ftp_alloc returns true 3 | --CREDITS-- 4 | Rodrigo Moyle 5 | #testfest PHPSP on 2009-06-20 6 | --FILE-- 7 | 18 | --EXPECT-- 19 | bool(true) -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_exec_basic.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing ftp_exec returns true 3 | --CREDITS-- 4 | Rodrigo Moyle 5 | #testfest PHPSP on 2009-06-20 6 | --FILE-- 7 | 18 | --EXPECT-- 19 | bool(true) -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_mlsd_missing_directory.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing ftp_mlsd returns false on server error 3 | --CREDITS-- 4 | Andreas Treichel 5 | --FILE-- 6 | 17 | --EXPECT-- 18 | bool(false) -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_rmdir_basic.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing ftp_rmdir returns true 3 | --CREDITS-- 4 | Rodrigo Moyle 5 | #testfest PHPSP on 2009-06-20 6 | --FILE-- 7 | 18 | --EXPECT-- 19 | bool(true) -------------------------------------------------------------------------------- /tests/swoole_runtime/proc/proc_open_pipes.inc: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | 17 | --EXPECT-- 18 | DONE 19 | -------------------------------------------------------------------------------- /examples/coroutine/http_client.php: -------------------------------------------------------------------------------- 1 | setHeaders(['Host' => 'localhost']); 6 | $cli->set(['http_proxy_host' => HTTP_PROXY_HOST, 'http_proxy_port' => HTTP_PROXY_PORT]); 7 | $result = $cli->get('/get?json=true'); 8 | var_dump($cli->body); 9 | // assert($result); 10 | // $ret = json_decode($cli->body, true); 11 | // assert(is_array($ret) and $ret['json'] == 'true'); 12 | }); 13 | -------------------------------------------------------------------------------- /examples/coroutine/list_coroutines.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | push(1, 0.1)); 13 | Assert::assert(!$channel->push(1, 0.1)); 14 | }); 15 | 16 | Swoole\Event::wait(); 17 | echo "DONE\n"; 18 | ?> 19 | --EXPECT-- 20 | DONE 21 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/nested_empty.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: coro nested empty 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 18 | --EXPECT-- 19 | co[1] start 20 | co[2] start 21 | co[2] exit 22 | co[1] exit 23 | -------------------------------------------------------------------------------- /tests/swoole_event/deprecated_event_wait.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_event: deprecated_event_wait 3 | --SKIPIF-- 4 | 11 | --FILE-- 12 | 22 | --EXPECT-- 23 | -------------------------------------------------------------------------------- /tests/swoole_global/unset_property_02.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_global: unset user class's parent internal property 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | capacity); 14 | ?> 15 | --EXPECTF-- 16 | Fatal error: Uncaught Error: Property capacity of class %s cannot be unset in %s:%d 17 | Stack trace: 18 | #0 {main} 19 | thrown in %s 20 | -------------------------------------------------------------------------------- /tests/swoole_runtime/sockets/basic/socket_accept_failure.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_runtime/sockets/basic: socket_accept() failure 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 17 | --EXPECTF-- 18 | bool(false) 19 | -------------------------------------------------------------------------------- /tests/swoole_coroutine_util/exec_sleep.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine_util: coroutine exec 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | 20 | --EXPECT-- 21 | DONE 22 | -------------------------------------------------------------------------------- /tests/swoole_pdo_odbc/server_info.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_pdo_odbc: test hook pgsql 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | getAttribute(PDO::ATTR_SERVER_INFO); 14 | Assert::eq(strtolower($info), 'mysql'); 15 | }); 16 | 17 | echo "Done\n"; 18 | ?> 19 | --EXPECTF-- 20 | Done 21 | -------------------------------------------------------------------------------- /tests/swoole_process/coro/start.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process/coro: start with coroutine 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | start(); 15 | Assert::assert($r > 0); 16 | $proc->close(); 17 | 18 | \Swoole\Process::wait(true); 19 | 20 | ?> 21 | --EXPECT-- 22 | SUCCESS 23 | -------------------------------------------------------------------------------- /tests/swoole_process/getaffinity.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: getAffinity 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 20 | --EXPECT-- 21 | -------------------------------------------------------------------------------- /tests/swoole_socket_coro/fd.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_socket_coro: fd 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 1) { 12 | Assert::assert(end($sockets)->fd === prev($sockets)->fd + 1); 13 | } 14 | } 15 | echo "DONE\n"; 16 | ?> 17 | --EXPECT-- 18 | DONE 19 | -------------------------------------------------------------------------------- /tests/swoole_ssh2/bug79631.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug 79631 (SSH disconnect segfault with SFTP (assertion failed)) 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 20 | --EXPECT-- 21 | done 22 | -------------------------------------------------------------------------------- /tests/swoole_timer/bug_4794_7.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_timer: #4794 Timer::add() (ERRNO 505): msec value[0] is invalid 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect("11.11.11.11", 80, 0.0005); 13 | Assert::false($r); 14 | Assert::eq($cli->errCode, SOCKET_ETIMEDOUT); 15 | ?> 16 | --EXPECT-- 17 | -------------------------------------------------------------------------------- /examples/coroutine/coro_invoke.php: -------------------------------------------------------------------------------- 1 | 1]); 4 | 5 | co::create(function() { 6 | 7 | 8 | $function = new ReflectionFunction('title'); 9 | 10 | $function->invoke(); 11 | echo "invoke444\n"; 12 | 13 | }); 14 | 15 | function title() { 16 | echo "333invoke_________________________________\n"; 17 | $tcpclient = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP); 18 | var_dump($tcpclient->connect('127.0.0.1', 9501, 1)); 19 | 20 | } 21 | 22 | echo "111\n"; 23 | -------------------------------------------------------------------------------- /examples/http2/streaming.php: -------------------------------------------------------------------------------- 1 | set([ 5 | 'open_http2_protocol' => 1, 6 | ]); 7 | 8 | /** 9 | * nghttp -v http://localhost:9501 10 | */ 11 | $http->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) { 12 | $n = 5; 13 | while ($n--) { 14 | $response->write("hello world, #$n
\n"); 15 | Co\System::sleep(1); 16 | } 17 | $response->end("hello world"); 18 | }); 19 | 20 | $http->start(); 21 | 22 | -------------------------------------------------------------------------------- /examples/server/reload_force2.php: -------------------------------------------------------------------------------- 1 | set([ 5 | "worker_num" => 4, 6 | "max_wait_time" => 1 7 | ]); 8 | $serv->on("WorkerStart", function (\Swoole\Server $server, $worker_id) { 9 | global $flag; 10 | echo "$worker_id [".$server->worker_pid."] start \n"; 11 | }); 12 | $serv->on('receive', function ($serv, $fd, $tid, $data) { 13 | echo "$tid recv $data\n"; 14 | if ($data) { 15 | sleep(100); 16 | } 17 | }); 18 | $serv->start(); 19 | -------------------------------------------------------------------------------- /examples/thread/nested_map.php: -------------------------------------------------------------------------------- 1 | uniqid(), 13 | 'b' => random_int(1000, 9999), 14 | ]; 15 | 16 | var_dump($map['map1']['key1']); 17 | var_dump($map['list1'][0]); 18 | 19 | var_dump($map['list1']->toArray()); 20 | 21 | var_dump($map['map2']); 22 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/dnslookup_1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: swoole_async_dns_lookup_coro 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 19 | --EXPECT-- 20 | -------------------------------------------------------------------------------- /tests/swoole_curl/multi/1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_curl/multi: 1 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 22 | --EXPECT-- 23 | Done 24 | -------------------------------------------------------------------------------- /tests/swoole_ftp/bug7216.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #7216 (ftp_mkdir returns nothing when server response is "257 OK.") 3 | --FILE-- 4 | 17 | --EXPECT-- 18 | bool(true) 19 | string(3) "CVS" 20 | -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_chmod_basic.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing ftp_chmod returns file mode 3 | --CREDITS-- 4 | Rodrigo Moyle 5 | #testfest PHPSP on 2009-06-20 6 | --FILE-- 7 | 18 | --EXPECT-- 19 | int(420) -------------------------------------------------------------------------------- /tests/swoole_library/exec/shell_exec/1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_library/exec/shell_exec: shell_exec 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 19 | --EXPECT-- 20 | -------------------------------------------------------------------------------- /examples/coroutine/coro_destruct.php: -------------------------------------------------------------------------------- 1 | test(); 28 | echo "end \n"; 29 | -------------------------------------------------------------------------------- /examples/coroutine/select/9.php: -------------------------------------------------------------------------------- 1 | push("chan1-$i"); 9 | echo "chan push [#$i] ret:".var_export($ret,1)."\n"; 10 | } 11 | }); 12 | 13 | go(function () use ($c1) { 14 | $ret = $c1->pop(); 15 | echo "chan pop ret:".var_export($ret,1)."\n"; 16 | co::sleep(1); 17 | $ret = $c1->pop(); 18 | echo "chan pop ret:".var_export($ret,1)."\n"; 19 | }); 20 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_server_port.stub.php: -------------------------------------------------------------------------------- 1 | on("connect", function(Swoole\Client $cli) { 4 | Assert::true(false, 'never here'); 5 | }); 6 | $cli->on("receive", function(Swoole\Client $cli, $data) { 7 | Assert::true(false, 'never here'); 8 | }); 9 | $cli->on("error", function(Swoole\Client $cli) { echo "connect timeout\n"; }); 10 | $cli->on("close", function(Swoole\Client $cli) { echo "close\n"; }); 11 | $cli->connect("11.11.11.11", 9000, 0.5); 12 | -------------------------------------------------------------------------------- /tests/swoole_channel_coro/10.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_channel_coro: 10 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | push("data"); 14 | }); 15 | Assert::same($chan->pop(0.001), "data"); 16 | Assert::false($chan->pop(0.001)); 17 | }); 18 | 19 | Swoole\Event::wait(); 20 | ?> 21 | --EXPECT-- 22 | -------------------------------------------------------------------------------- /tests/swoole_client_sync/enableSSL_2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_client_sync: enableSSL 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect("www.baidu.com", 443, 2.0)); 11 | 12 | try { 13 | $cli->enableSSL(function (){}); 14 | } catch (\Throwable $e) { 15 | Assert::contains($e->getMessage(), 'not support `onSslReady` callback'); 16 | } 17 | ?> 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /examples/runtime/curl.php: -------------------------------------------------------------------------------- 1 | set([ 5 | "worker_num" => 4, 6 | "max_wait_time" => 1 7 | ]); 8 | $serv->on("WorkerStart", function (\Swoole\Server $server, $worker_id) { 9 | global $flag; 10 | echo "$worker_id [".$server->worker_pid."] start \n"; 11 | }); 12 | $serv->on('receive', function ($serv, $fd, $tid, $data) { 13 | echo "$tid recv $data\n"; 14 | if ($data) { 15 | sleep(100); 16 | } 17 | }); 18 | $serv->start(); 19 | -------------------------------------------------------------------------------- /tests/include/api/swoole_websocket_server/send_small_request_data.php: -------------------------------------------------------------------------------- 1 | connect(); 10 | 11 | $data = ""; 12 | for ($i = 0; $i < 100; $i++) 13 | { 14 | $client->send($data); 15 | $response = $client->recv(); 16 | Assert::same($response, "SUCCESS", "response failed"); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/swoole_coroutine/new_process.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: new process 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | start(); 11 | }); 12 | ?> 13 | --EXPECTF-- 14 | Fatal error: Uncaught Swoole\Error: must be forked outside the coroutine in %s:%d 15 | Stack trace: 16 | #0 %s(5): Swoole\Process->start() 17 | %A 18 | thrown in %s on line %d 19 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/new_server.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: new server 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | on('receive', function () { 11 | }); 12 | $server->start(); 13 | }); 14 | ?> 15 | --EXPECTF-- 16 | Warning: Swoole\Server::start(): The event-loop has already been created, unable to start %s in %s on line %d 17 | -------------------------------------------------------------------------------- /examples/coroutine/proc_open.php: -------------------------------------------------------------------------------- 1 | array("pipe", "r"), 7 | 1 => array("pipe", "w"), 8 | 2 => array("pipe", "w"), 9 | ); 10 | 11 | $process = proc_open('unknown', $descriptorspec, $pipes); 12 | 13 | var_dump($pipes); 14 | 15 | var_dump(fread($pipes[2], 8192)); 16 | 17 | $return_value = proc_close($process); 18 | 19 | echo "command returned $return_value\n"; 20 | }); -------------------------------------------------------------------------------- /examples/coroutine/tcp_backend_serv.php: -------------------------------------------------------------------------------- 1 | set(array( 4 | 'worker_num' => 1, //工作进程数量 5 | 'daemonize' => true, //是否作为守护进程 6 | )); 7 | $serv->on('connect', function ($serv, $fd){ 8 | echo "Client:Connect.\n"; 9 | }); 10 | $serv->on('receive', function ($serv, $fd, $reactor_id, $data) { 11 | $serv->send($fd, 'Swoole: '.$data); 12 | $serv->close($fd); 13 | }); 14 | $serv->on('close', function ($serv, $fd) { 15 | echo "Client: Close.\n"; 16 | }); 17 | $serv->start(); 18 | -------------------------------------------------------------------------------- /examples/runtime/ssl.php: -------------------------------------------------------------------------------- 1 | \n"; 8 | } else { 9 | $http = "GET / HTTP/1.0\r\nAccept: */*User-Agent: Lowell-Agent\r\nHost: www.baidu.com\r\nConnection: Close\r\n\r\n"; 10 | fwrite($fp, $http); 11 | while (!feof($fp)) { 12 | echo fgets($fp, 1024); 13 | } 14 | fclose($fp); 15 | } 16 | }); 17 | -------------------------------------------------------------------------------- /examples/thread/socket.php: -------------------------------------------------------------------------------- 1 | join(); 17 | } else { 18 | $map = $args[0]; 19 | $sock = $map['socket']; 20 | $retval = socket_connect($sock, '127.0.0.1', 80); 21 | } 22 | -------------------------------------------------------------------------------- /examples/websocket/client.html: -------------------------------------------------------------------------------- 1 | 20 | -------------------------------------------------------------------------------- /scripts/install-deps-on-ubuntu.sh: -------------------------------------------------------------------------------- 1 | apt install -y cmake make gcc g++ \ 2 | iputils-ping \ 3 | libc-ares-dev \ 4 | libssl-dev \ 5 | libcurl4-openssl-dev \ 6 | libmariadb-dev \ 7 | libaio-dev \ 8 | zlib1g-dev \ 9 | sqlite3 libsqlite3-dev \ 10 | libbrotli-dev \ 11 | libpq-dev \ 12 | unixodbc-dev \ 13 | firebird-dev \ 14 | libzstd-dev \ 15 | libssh2-1-dev 16 | 17 | # The built-in liburing version of Ubuntu is 0.7, which is too low. We must install liburing through the source code 18 | # liburing-dev 19 | -------------------------------------------------------------------------------- /tests/swoole_coroutine_util/exec.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine_util: exec 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 20 | --EXPECT-- 21 | -------------------------------------------------------------------------------- /tests/swoole_curl/multi/2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_curl/multi: 2 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 0.2]); 19 | echo "Done\n"; 20 | }); 21 | ?> 22 | --EXPECT-- 23 | Done 24 | -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_rawlist_basic2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing ftp_rawlist returns false on server error 3 | --CREDITS-- 4 | Rodrigo Moyle 5 | #testfest PHPSP on 2009-06-20 6 | --FILE-- 7 | 18 | --EXPECT-- 19 | bool(false) -------------------------------------------------------------------------------- /tests/swoole_runtime/hook_enable_coroutine.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_runtime: enableCoroutine 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 22 | --EXPECT-- 23 | -------------------------------------------------------------------------------- /tests/swoole_timer/next_round.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_timer: timer round control 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 22 | --EXPECT-- 23 | -------------------------------------------------------------------------------- /examples/runtime/odbc.php: -------------------------------------------------------------------------------- 1 | query("select sleep(1) s"); 10 | var_dump($res->fetchAll()); 11 | $dbh = null; 12 | } catch (PDOException $exception) { 13 | echo $exception->getMessage(); 14 | exit; 15 | } 16 | } 17 | 18 | Co::set(['trace_flags' => SWOOLE_TRACE_CO_ODBC, 'log_level' => SWOOLE_LOG_DEBUG]); 19 | 20 | Co\run(function () { 21 | test(); 22 | }); 23 | -------------------------------------------------------------------------------- /examples/ssl/websocket_client.html: -------------------------------------------------------------------------------- 1 | 20 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/dnslookup_ipv6.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: dns Lookup IPv6 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 19 | --EXPECT-- 20 | -------------------------------------------------------------------------------- /tests/swoole_event/dispatch.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_event: dispatch 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 22 | --EXPECT-- 23 | loop 24 | loop 25 | Tick 26 | loop 27 | Tick 28 | loop 29 | Tick 30 | loop 31 | Tick 32 | -------------------------------------------------------------------------------- /tests/swoole_global/too_many_objects.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_global: too many objects 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | listen('127.0.0.1', get_one_free_port(), SWOOLE_TCP); 14 | echo "DONE\n"; 15 | ?> 16 | --EXPECT-- 17 | DONE 18 | -------------------------------------------------------------------------------- /tests/swoole_pdo_oracle/pdo_oracle.inc: -------------------------------------------------------------------------------- 1 | getMessage()); 11 | } 12 | } 13 | 14 | public static function create(): PDO 15 | { 16 | $db = new PDO(ORACLE_TNS, ORACLE_USER, ORACLE_PASSWORD); 17 | $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); 18 | return $db; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/swoole_stdext/typed_array/sort.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_stdext/typed_array: sort 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | ', [1243, 3434, 5453, 4532, 2, 3454, 5233, 655, 234, 6, 2356, 4554]); 10 | Assert::true($arr->isList()); 11 | Assert::true($arr->isTyped()); 12 | 13 | sort($arr); 14 | Assert::true($arr->isTyped()); 15 | 16 | shuffle($arr); 17 | Assert::true($arr->isTyped()); 18 | 19 | ?> 20 | --EXPECT-- 21 | -------------------------------------------------------------------------------- /tests/swoole_thread/map2array.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_thread: map to array 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 1111]); 18 | $ls = $LURDATE[$time]->toArray(); 19 | foreach ($ls as $k => $v) { 20 | unset($LURDATE[$time][$k]); 21 | } 22 | unset($LURDATE[$time]); 23 | ?> 24 | --EXPECTF-- 25 | -------------------------------------------------------------------------------- /examples/coroutine/coro_array_map.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 9501, 1); 15 | echo "co resume : connect ret = ".var_export($res,1)."\n"; 16 | echo "map func end \n"; 17 | }); 18 | } 19 | echo "main end\n"; 20 | -------------------------------------------------------------------------------- /examples/http/no-compression.php: -------------------------------------------------------------------------------- 1 | on('request', function ($req, Swoole\Http\Response $resp) use ($http) { 6 | if ($req->server['request_uri'] == '/') { 7 | $resp->header('Content-Encoding', ''); 8 | $resp->end(str_repeat('A', 1024)); 9 | } elseif ($req->server['request_uri'] == '/gzip') { 10 | $resp->end(str_repeat('A', 1024)); 11 | } else { 12 | $resp->status(404); 13 | $resp->end(); 14 | } 15 | }); 16 | 17 | $http->start(); 18 | -------------------------------------------------------------------------------- /examples/socket_coro/client.php: -------------------------------------------------------------------------------- 1 | connect('localhost', 9601); 6 | while ($retval) 7 | { 8 | $n = $socket->send("hello"); 9 | var_dump($n); 10 | 11 | $data = $socket->recv(); 12 | var_dump($data); 13 | 14 | if (empty($data)) { 15 | $socket->close(); 16 | break; 17 | } 18 | co::sleep(1.0); 19 | } 20 | var_dump($retval, $socket->errCode); 21 | }); 22 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_http_server_coro.stub.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | connect('www.baidu.com', 80); 11 | Assert::true($cli->close()); 12 | Assert::false($cli->close()); 13 | Assert::eq($cli->errCode, SWOOLE_ERROR_CLIENT_NO_CONNECTION); 14 | }); 15 | Swoole\Event::wait(); 16 | ?> 17 | --EXPECT-- 18 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/resume_loop.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: resume loop 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 0) { 14 | Co::resume(array_shift($cos)); 15 | } 16 | }); 17 | } 18 | Co::resume(array_shift($cos)); 19 | echo "DONE\n"; 20 | ?> 21 | --EXPECT-- 22 | DONE 23 | -------------------------------------------------------------------------------- /tests/swoole_function/swoole_set_process_name.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_function: set process name 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 20 | --EXPECT-- 21 | SUCCESS 22 | -------------------------------------------------------------------------------- /tests/swoole_lock/lock_timeout.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_lock: lock timeout 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | lock()); 11 | 12 | $start = microtime(true); 13 | $ret = $lock->lock(LOCK_EX, 0.2); 14 | Assert::false($ret); 15 | $end = microtime(true); 16 | 17 | Assert::eq($lock->errCode, SOCKET_ETIMEDOUT); 18 | Assert::greaterThanEq($end - $start, 0.2); 19 | 20 | ?> 21 | --EXPECT-- 22 | bool(true) 23 | -------------------------------------------------------------------------------- /examples/coroutine/fgets.php: -------------------------------------------------------------------------------- 1 | '127.0.0.1', 9 | 'user' => 'root', 10 | 'password' => 'root', 11 | 'database' => 'test', 12 | ); 13 | 14 | echo "connect\n"; 15 | $ret1 = $db->connect($server); 16 | var_dump($ret1); 17 | 18 | echo "prepare [1]\n"; 19 | $stmt1 = $db->prepare('show tables'); 20 | echo "execute\n"; 21 | $ret1 = $stmt1->execute([]); 22 | var_dump($ret1); 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/array_walk.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: array_walk 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 20 | --EXPECTF-- 21 | DONE 22 | -------------------------------------------------------------------------------- /tests/swoole_runtime/hook_set_flags.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_runtime: set hook flags 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 0]); 12 | 13 | Co\run(function () { 14 | Assert::eq(Swoole\Runtime::getHookFlags(), 0); 15 | }); 16 | 17 | Co::set(['hook_flags' => SWOOLE_HOOK_CURL]); 18 | 19 | Co\run(function () { 20 | Assert::eq(Swoole\Runtime::getHookFlags(), SWOOLE_HOOK_CURL); 21 | }); 22 | 23 | ?> 24 | --EXPECT-- 25 | -------------------------------------------------------------------------------- /tests/swoole_stdext/array_method/1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_stdext/array_method: 1 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | ', ["lemon", "orange", "banana", "apple"]); 10 | $sorted_array = array("apple", "banana", "lemon", "orange",); 11 | 12 | $ref = &$array; 13 | $ref->sort(SORT_NATURAL | SORT_FLAG_CASE); 14 | 15 | Assert::same($array, $sorted_array); 16 | Assert::same($ref, $sorted_array); 17 | ?> 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /tests/swoole_timer/verify.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_timer: verify timer 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 19 | --EXPECT-- 20 | DONE 21 | -------------------------------------------------------------------------------- /tools/send-http-data.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 6 | --FILE-- 7 | pop(0.001); 12 | Assert::false($ret); 13 | }); 14 | function foo() 15 | { 16 | $chan = new \Swoole\Coroutine\Channel(); 17 | go(function () use ($chan) { 18 | // nothing 19 | }); 20 | return $chan; 21 | } 22 | 23 | ?> 24 | --EXPECT-- 25 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/bailout/error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine/bailout: error 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 19 | --EXPECTF-- 20 | Fatal error: Uncaught Error in %s:%d 21 | Stack trace: 22 | %A 23 | thrown in %s on line %d 24 | shutdown 25 | -------------------------------------------------------------------------------- /tests/swoole_ftp/filesize_large.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Verify php can handle filesizes >32bit 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 23 | --EXPECT-- 24 | int(5368709120) -------------------------------------------------------------------------------- /tests/swoole_runtime/stream_context_pass_null.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_runtime: stream context pass null 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 18 | --EXPECT-- 19 | bool(true) 20 | -------------------------------------------------------------------------------- /tests/swoole_socket_coro/ssl.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_socket_coro: ssl client 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 20 | --EXPECT-- 21 | -------------------------------------------------------------------------------- /tests/swoole_stdext/typed_array/8.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_stdext/typed_array: 8 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | '); 10 | 11 | $arr[] = 1; 12 | $arr[0] += 10; 13 | Assert::eq($arr[0], 11); 14 | 15 | try { 16 | $arr[0] .= "hello world"; 17 | } catch (TypeError $e) { 18 | Assert::true($e->getMessage()->contains('Array value type mismatch')); 19 | echo "DONE\n"; 20 | } 21 | 22 | ?> 23 | --EXPECT-- 24 | DONE 25 | -------------------------------------------------------------------------------- /examples/coroutine/defer.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /examples/coroutine/mysql_query.php: -------------------------------------------------------------------------------- 1 | 1]); 4 | 5 | co::create(function() { 6 | 7 | 8 | $function = new ReflectionFunction('title'); 9 | 10 | $function->invoke(); 11 | echo "invoke444\n"; 12 | 13 | }); 14 | 15 | function title() { 16 | echo "333invoke_________________________________\n"; 17 | $tcpclient = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP); 18 | var_dump($tcpclient->connect('127.0.0.1', 9501, 1)); 19 | 20 | } 21 | 22 | echo "111\n"; 23 | 24 | 25 | echo "222\n"; 26 | co::go(); 27 | -------------------------------------------------------------------------------- /examples/coroutine/select/poptimeout.php: -------------------------------------------------------------------------------- 1 | pop(1); 9 | $end = microtime(1); 10 | echo "chan pop ret:".var_export($ret,1)." error:".$c1->errCode."\n"; 11 | echo "use time:".($end-$start)."s\n"; 12 | 13 | }); 14 | 15 | go(function () use ($c1) { 16 | co::sleep(2); 17 | echo "sleep 2\n"; 18 | $ret = $c1->push("chan-1"); 19 | echo "chan push ret:".var_export($ret,1)." error:".$c1->errCode."\n"; 20 | }); 21 | -------------------------------------------------------------------------------- /examples/coroutine/server/tcp.php: -------------------------------------------------------------------------------- 1 | handle(function (Connection $conn) { 10 | while (true) { 11 | 12 | $data = $conn->recv(); 13 | if (!$data) { 14 | break; 15 | } 16 | $conn->send("hello $data"); 17 | } 18 | $conn->close(); 19 | }); 20 | 21 | $server->start(); 22 | }); 23 | 24 | Swoole\Event::wait(); 25 | -------------------------------------------------------------------------------- /examples/thread/pipe.php: -------------------------------------------------------------------------------- 1 | recv(8192), PHP_EOL; 12 | $thread->join(); 13 | }); 14 | } else { 15 | $sockets = $args[0]; 16 | Co\run(function () use ($sockets) { 17 | sleep(1); 18 | $sockets[1]->send(uniqid()); 19 | }); 20 | } 21 | -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_mlsd_empty_directory.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ftp_mlsd() must not return false on empty directories 3 | --FILE-- 4 | 19 | --EXPECT-- 20 | bool(true) 21 | array(0) { 22 | } 23 | bool(false) -------------------------------------------------------------------------------- /tests/swoole_stdext/typed_array/9.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_stdext/typed_array: 9 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | '); 10 | $array[999] = random_bytes(128); 11 | 12 | try { 13 | $a = typed_array(''); 14 | $array[888] = $a; 15 | } catch (TypeError $e) { 16 | Assert::true($e->getMessage()->contains('Array value type mismatch')); 17 | echo "DONE\n"; 18 | } 19 | 20 | ?> 21 | --EXPECT-- 22 | DONE 23 | -------------------------------------------------------------------------------- /examples/client/simple.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 9501, 0.5, 0); 6 | if (!$ret) { 7 | echo "Over flow. errno=" . $client->errCode; 8 | die("\n"); 9 | } 10 | $clients[] = $client; 11 | } 12 | sleep(1); 13 | while (1) { 14 | foreach ($clients as $client) { 15 | $client->send("sss"); 16 | $data = $client->recv(); 17 | var_dump($data); 18 | } 19 | sleep(1); 20 | } 21 | -------------------------------------------------------------------------------- /examples/table/usage.php: -------------------------------------------------------------------------------- 1 | column('id', Swoole\Table::TYPE_INT); 4 | $table->column('name', Swoole\Table::TYPE_STRING, 64); 5 | $table->column('num', Swoole\Table::TYPE_FLOAT); 6 | $table->create(); 7 | 8 | $table->set('a', array('id' => 1, 'name' => 'swoole-co-uk', 'num' => 3.1415)); 9 | $table->set('b', array('id' => 2, 'name' => "swoole-uk", 'num' => 3.1415)); 10 | $table->set('hello@swoole.co.uk', array('id' => 3, 'name' => 'swoole', 'num' => 3.1415)); 11 | 12 | var_dump($table->get('a')); 13 | var_dump($table->get('b', 'name')); 14 | -------------------------------------------------------------------------------- /tests/swoole_process/write.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_process: write 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | write("SUCCESS"); 11 | Assert::same($r, 7); 12 | }); 13 | $r = $proc->start(); 14 | Assert::assert($r > 0); 15 | 16 | Swoole\Timer::after(10, function() use($proc) { 17 | echo $proc->read(); 18 | }); 19 | 20 | \Swoole\Process::wait(true); 21 | ?> 22 | --EXPECT-- 23 | SUCCESS 24 | -------------------------------------------------------------------------------- /tests/swoole_runtime/library.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_runtime: library 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 18 | --EXPECT-- 19 | bool(true) 20 | -------------------------------------------------------------------------------- /examples/coroutine/select/4.php: -------------------------------------------------------------------------------- 1 | push("data-$i"); 10 | echo "push [#$i] ret:".var_export($ret,1)."\n"; 11 | } 12 | }); 13 | 14 | go(function () use ($c1, $num) { 15 | echo "pop start\n"; 16 | for ($i=0;$i<$num;$i++) 17 | { 18 | $ret = $c1->pop(); 19 | echo "pop [#$i] ret:".var_export($ret,1)."\n"; 20 | } 21 | }); 22 | echo "main end\n"; 23 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_timer.stub.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | 21 | --EXPECT-- 22 | foo 23 | bar 24 | -------------------------------------------------------------------------------- /tests/swoole_library/exec/exec/1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_library/exec/exec: Test exec 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 20 | --EXPECT-- 21 | -------------------------------------------------------------------------------- /tests/swoole_runtime/file_lock/lock_nb.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_runtime/file_lock: lock_nb 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 19 | --EXPECTF-- 20 | -------------------------------------------------------------------------------- /examples/client/recv_1m.php: -------------------------------------------------------------------------------- 1 | connect('127.0.0.1', 9509, 60); 5 | $c->send("AAAAAAAAAAAAAAAA"); 6 | 7 | $n_bytes = 0; 8 | 9 | while (true) 10 | { 11 | $line = $c->recv(); 12 | if ($line === false) 13 | { 14 | echo "recv failed.\n"; 15 | break; 16 | } 17 | elseif (empty($line)) 18 | { 19 | echo "recv $n_bytes bytes\n"; 20 | break; 21 | } 22 | else 23 | { 24 | fwrite($f, $line); 25 | $n_bytes += strlen($line); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/coroutine/select/2.php: -------------------------------------------------------------------------------- 1 | pop(); 10 | echo "pop [#$i] ret:".var_export($ret,1)."\n"; 11 | } 12 | }); 13 | 14 | go(function () use ($c1,$num) { 15 | echo "push start\n"; 16 | for ($i=0;$i<$num;$i++) 17 | { 18 | $ret = $c1->push("data-$i"); 19 | echo "push [#$i] ret:".var_export($ret,1)."\n"; 20 | } 21 | 22 | }); 23 | echo "main end\n"; 24 | -------------------------------------------------------------------------------- /examples/event/stream.php: -------------------------------------------------------------------------------- 1 | \n"); 5 | } 6 | fwrite($fp, "HELLO world"); 7 | 8 | function stream_onRead($fp) 9 | { 10 | echo fread($fp, 1024)."\n"; 11 | sleep(1); 12 | Swoole\Event::write($fp, "hello world"); 13 | //Swoole\Event::set($fp, null, null, SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE); 14 | //Swoole\Event::del($fp); 15 | //fclose($fp); 16 | } 17 | 18 | 19 | Swoole\Event::add($fp, 'stream_onRead'); 20 | 21 | echo "start\n"; 22 | Swoole\Event::wait(); 23 | -------------------------------------------------------------------------------- /examples/ssl/passphrase.php: -------------------------------------------------------------------------------- 1 | set(array( 4 | "ssl_key_file" => __DIR__ . '/ssl.key', 5 | "ssl_cert_file" => __DIR__ . '/ssl.crt', 6 | 'ssl_passphrase' => '5524001', 7 | )); 8 | if (!$client->connect('127.0.0.1', 9501, -1)) 9 | { 10 | exit("connect failed. Error: {$client->errCode}\n"); 11 | } 12 | echo "connect ok\n"; 13 | sleep(1); 14 | 15 | for ($i = 0; $i < 1000; $i++) 16 | { 17 | $client->send("hello world-" . str_repeat('A', $i) . "\n"); 18 | echo $client->recv(); 19 | } 20 | sleep(1); 21 | -------------------------------------------------------------------------------- /examples/thread/benchmark.php: -------------------------------------------------------------------------------- 1 | 5 | --FILE-- 6 | 0.005]); 10 | 11 | Co\run(function () { 12 | $cli = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP); 13 | Assert::assert(!@$cli->connect('xxx.66xx.6855.xxx.xx'.rand(1000, 9999) . time(), 80)); 14 | Assert::same($cli->errCode, SWOOLE_ERROR_DNSLOOKUP_RESOLVE_TIMEOUT); 15 | }); 16 | ?> 17 | --EXPECT-- 18 | -------------------------------------------------------------------------------- /tests/swoole_client_coro/getsockname.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_client_coro: getsockname 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect('www.baidu.com', 80); 13 | $info = $conn->getsockname(); 14 | Assert::assert(filter_var($info['host'], FILTER_VALIDATE_IP)); 15 | Assert::greaterThan($info['port'], 0); 16 | } 17 | ); 18 | ?> 19 | --EXPECT-- 20 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/nested1.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: coro channel 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 21 | --EXPECT-- 22 | co[1] start 23 | end 24 | co[2] start 25 | co[1] exit 26 | co[2] exit 27 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/nested2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: coro nested2 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 21 | --EXPECT-- 22 | co[1] start 23 | co[2] start 24 | end 25 | co[1] exit 26 | co[2] exit 27 | -------------------------------------------------------------------------------- /tests/swoole_coroutine/nested3.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_coroutine: coro nested3 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 21 | --EXPECT-- 22 | co[1] start 23 | co[2] start 24 | end 25 | co[2] exit 26 | co[1] exit 27 | -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_alloc_basic2.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing ftp_alloc returns true 3 | --CREDITS-- 4 | Rodrigo Moyle 5 | #testfest PHPSP on 2009-06-20 6 | --FILE-- 7 | 19 | --EXPECT-- 20 | bool(true) 21 | string(20) "1024 bytes allocated" -------------------------------------------------------------------------------- /tests/swoole_ftp/ftp_nb_put.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Testing ftp_nb_put basic functionality 3 | --CREDITS-- 4 | Gabriel Caruso (carusogabriel34@gmail.com) 5 | --FILE-- 6 | 20 | --EXPECT-- 21 | int(1) -------------------------------------------------------------------------------- /tests/swoole_redis_server/getHandler.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_redis_server: getHandler 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setHandler('GET', function ($fd, $data) use ($server) { 13 | $server->send($fd, Server::format(Server::STRING, "hello")); 14 | }); 15 | 16 | $callback = $server->getHandler('GET'); 17 | Assert::assert(is_callable($callback)); 18 | 19 | ?> 20 | --EXPECT-- 21 | -------------------------------------------------------------------------------- /tests/swoole_table/bug_2263.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_table: bug_2263 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | column('data', Table::TYPE_STRING, 1); 13 | $table->create(); 14 | 15 | $table->set("1234567890", ['data' => '1']); 16 | $table->set("44984", ['data' => '2']); 17 | 18 | $table->del("1234567890"); 19 | 20 | foreach($table as $ip => $row) { 21 | echo $ip."\n"; 22 | } 23 | 24 | ?> 25 | --EXPECT-- 26 | 44984 27 | -------------------------------------------------------------------------------- /ext-src/stubs/php_swoole_ex.stub.php: -------------------------------------------------------------------------------- 1 | 7 | --FILE-- 8 | on('workerStart', function (Swoole\Process\Pool $pool, int $workerId) use ($pid) 14 | { 15 | Assert::assert($pool->master_pid == $pid); 16 | posix_kill($pid, SIGTERM); 17 | sleep(20); 18 | echo "ERROR\n"; 19 | }); 20 | 21 | $pool->start(); 22 | ?> 23 | --EXPECT-- 24 | -------------------------------------------------------------------------------- /tests/swoole_stdext/typed_array/resource.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_stdext/typed_array: resource 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | '); 10 | $map['a'] = fopen(__FILE__, 'r'); 11 | Assert::eq(get_resource_type($map['a']), 'stream'); 12 | 13 | try { 14 | $map['b'] = 1; 15 | } catch (Throwable $e) { 16 | Assert::true($e->getMessage()->contains('Array value type mismatch')); 17 | echo "DONE\n"; 18 | } 19 | ?> 20 | --EXPECT-- 21 | DONE 22 | -------------------------------------------------------------------------------- /tests/swoole_thread/yield.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_thread: thread status 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | isAlive()); 16 | $t1->detach(); 17 | Thread::yield(); 18 | usleep(10); 19 | Assert::true($t1->isAlive()); 20 | while (Thread::activeCount() > 1) { 21 | usleep(10); 22 | } 23 | Assert::false($t1->isAlive()); 24 | ?> 25 | --EXPECT-- 26 | -------------------------------------------------------------------------------- /tests/swoole_timer/bug_4794_5.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | swoole_timer: #4794 Timer::add() (ERRNO 505): msec value[0] is invalid 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 18 | --EXPECT-- 19 | -------------------------------------------------------------------------------- /examples/coroutine/behavior/while2.php: -------------------------------------------------------------------------------- 1 | 5000, 4 | ]); 5 | $s = microtime(1); 6 | echo "start\n"; 7 | 8 | $flag = 1; 9 | go(function () use (&$flag){ 10 | echo "coro 1 start\n"; 11 | $i = 0; 12 | while($flag) { 13 | $i ++; 14 | echo "$i\n"; 15 | sleep(1); 16 | } 17 | echo "coro 1 can exit\n"; 18 | }); 19 | 20 | $t = microtime(1); 21 | $u = $t-$s; 22 | echo "use time $u s\n"; 23 | go(function () use (&$flag){ 24 | echo " coro 2 set flag = false\n"; 25 | $flag = false; 26 | }); 27 | echo "end\n"; 28 | -------------------------------------------------------------------------------- /examples/coroutine/select/test.php: -------------------------------------------------------------------------------- 1 | push($i); 9 | echo "push {$i} res:".var_export($ret, 1)."\n"; 10 | }); 11 | }; 12 | go(function ()use ($chan){ 13 | $bool = true; 14 | while ($bool){ 15 | $data = $chan->pop(); 16 | echo "pop res:".var_export($data, 1)."\n"; 17 | if($data===false){ 18 | $bool = false; 19 | } 20 | //var_dump($data); 21 | } 22 | }); 23 | --------------------------------------------------------------------------------