123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- declare(strict_types=0);
- define('MOBILE_SERVER',true);
- define('USE_COROUTINE',true);
- define('SUPPORT_PTHREAD',false);
- define('APP_ID', 'sender');
- define('BASE_ROOT_PATH',str_replace('/server','',dirname(__FILE__)));
- define('BASE_PATH',BASE_ROOT_PATH . '/server');
- 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');
- Co::set(['hook_flags' => SWOOLE_HOOK_NATIVE_CURL|SWOOLE_HOOK_SLEEP]);
- class RefillSender
- {
- const co_orders = 100000;
- public function sendex()
- {
- $pThis = $this;
- $time = time() * 1000;
- for ($i = 0;$i < self::co_orders;)
- {
- $res = Swoole\Coroutine::stats();
- $num = $res['coroutine_num'];
- if($num > 1000) {
- sleep(1);
- continue;
- }
- $i++;
- Log::record(__FUNCTION__ . " index={$i}",Log::DEBUG);
- go(function () use ($pThis,$time,$i) {
- $pThis->push_order(1092, $time, $i);
- });
- }
- }
- private function push_order($mchid,$time,$index)
- {
- $pid = getmypid();
- $cid = Swoole\Coroutine::getCid();
- $order_sn = "{$pid}{$cid}{$time}" . sprintf("%'010d",$index);
- $notify_url = "https://test.xyzshops.cn/mobile/callback/bridge_test.php";
- $params = [ 'mchid' => $mchid,
- 'amount' => 30,
- 'order_sn' => $order_sn,
- 'cardno' => '13911129867',
- "act" => "refill",
- "op" => "add",
- 'notifyurl' => $notify_url
- ];
- $proxy = new refill_proxy("210fe406954220f56085997d6a4c5b80");
- $resp = $proxy->send("https://test.xyzshops.cn/mobile/index.php", $params);
- Log::record("resp={$resp}",Log::DEBUG);
- }
- }
- $process_count = 2;
- $workers = [];
- for ($i = 0; $i < $process_count;$i++)
- {
- $process = new Swoole\Process(function(Swoole\Process $worker)
- {
- Base::run_util();
- set_error_handler('handle_error');
- go(function () {
- $sender = new RefillSender();
- $sender->sendex();
- });
- }, false, false, true);
- $pid = $process->start();
- $workers[$pid] = $process;
- }
- Log::record("main process start wait sub process....",Log::DEBUG);
- while (true)
- {
- if($status = Swoole\Process::wait(true)) {
- Log::record("Sub process #{$status['pid']} quit, code={$status['code']}, signal={$status['signal']}",Log::DEBUG);
- }
- else
- {
- foreach ($workers as $pid => $worker)
- {
- Swoole\Process::kill($pid,SIGTERM);
- if($status = Swoole\Process::wait(true)) {
- Log::record("Graceful Recycled #{$status['pid']}, code={$status['code']}, signal={$status['signal']}",Log::DEBUG);
- }
- }
- break;
- }
- }
- Log::record("Quit all",Log::DEBUG);
|