12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- declare(strict_types=0);
- define('MOBILE_SERVER', true);
- define('USE_COROUTINE', true);
- define('SUPPORT_PTHREAD', false);
- define('APP_ID', 'coredis');
- define('BASE_ROOT_PATH', str_replace('/server', '', dirname(__FILE__)));
- define('BASE_PATH', BASE_ROOT_PATH . '/server');
- define('COROUTINE_HOOK_TCP',true);
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_CORE_PATH . '/framework/function/http.php');
- require_once(BASE_HELPER_PATH . '/refill_proxy.php');
- require_once(BASE_CORE_PATH . '/framework/libraries/CoPool.php');
- require_once(BASE_CORE_PATH . '/framework/libraries/CoRedisPool.php');
- Co::set(['hook_flags' => SWOOLE_HOOK_NATIVE_CURL | SWOOLE_HOOK_SLEEP | SWOOLE_HOOK_TCP]);
- class RedisPoolTest
- {
- public function setval()
- {
- for ($i = 0; $i < 200; $i++)
- {
- Log::record("cur index = {$i}",Log::DEBUG);
- go(function ()
- {
- $key = '100905';
- $ins = Cache::getInstance('cacheredis');
- $ret = $ins->incr($key);
- Log::record("setval value={$ret}",Log::DEBUG);
- });
- }
- }
- public function readval()
- {
- for ($i = 0; $i < 200; $i++)
- {
- Log::record("cur index = {$i}",Log::DEBUG);
- go(function ()
- {
- $key = '100905';
- $ins = Cache::getInstance('cacheredis');
- $ret = $ins->get_org($key);
- Log::record("readval value={$ret}",Log::DEBUG);
- });
- }
- }
- }
- Swoole\Coroutine::set(['max_coroutine' => 500]);
- go(function ()
- {
- Base::run_util();
- $key = '100905';
- $ins = Cache::getInstance('cacheredis');
- $ret = $ins->incr($key);
- Log::record("setval value={$ret}",Log::DEBUG);
- $test = new RedisPoolTest();
- for ($i = 0; $i < 100; $i++)
- {
- Log::record("first index = {$i}",Log::DEBUG);
- go(function () use($test)
- {
- $test->setval();
- });
- sleep(1);
- }
- for ($i = 0; $i < 100; $i++)
- {
- Log::record("second index = {$i}",Log::DEBUG);
- go(function () use($test)
- {
- $test->readval();
- });
- sleep(1);
- }
- sleep(10);
- CoRedisPool::instance()->stop();
- });
- //docker-compose run phpswoole php /var/www/html/server/coredis.php
|