@@ -592,10 +592,10 @@ protected static function initWorkers()
592
592
$ worker ->coroutineMessage = function ($ connection ,$ recv_buffer ) use ($ worker ){
593
593
//process request,if have commond yied push to coroutine queue
594
594
$ r = call_user_func ($ worker ->onMessage , $ connection , $ recv_buffer );
595
- if (method_exists ($ r ,"current " )&& defined ( " WORKERMAN_COROUTINE_LOOP_TIME " ) ){
596
- $ r ->current ();//first triger coroutine
597
- //将任务加入到协程队列
598
- array_push ( static ::$ g_coroutine_array, $ r ) ;
595
+ if (method_exists ($ r ,"current " )){
596
+ $ hash_key = $ r ->current ();//first triger coroutine
597
+ //push to coroutine queue
598
+ static ::$ g_coroutine_array[ $ hash_key ] = $ r ;
599
599
}
600
600
};
601
601
}
@@ -2152,9 +2152,6 @@ public function run()
2152
2152
exit (250 );
2153
2153
}
2154
2154
}
2155
- if (defined ("WORKERMAN_COROUTINE_LOOP_TIME " )){
2156
- static ::$ globalEvent ->add (WORKERMAN_COROUTINE_LOOP_TIME , EventInterface::EV_TIMER , array ($ this , 'coroutinesLoopController ' ));
2157
- }
2158
2155
// Main loop.
2159
2156
static ::$ globalEvent ->loop ();
2160
2157
}
@@ -2274,21 +2271,18 @@ public function acceptUdpConnection($socket)
2274
2271
* @param $order the coroutine order
2275
2272
* @return void
2276
2273
*/
2277
- public function coroutinesLoopController (){
2278
- static $ idx = -1 ;
2279
- $ cnt = count (static ::$ g_coroutine_array );
2280
- if ($ idx <0 ){
2281
- $ idx = $ cnt -1 ;
2282
- }
2283
- if ($ cnt >0 ){
2284
- $ it = static ::$ g_coroutine_array [$ idx ];
2285
- if ($ it ->valid ()){
2286
- $ it ->next ();
2287
- }else {
2288
- //coroutine done,delete coroutine from queue
2289
- array_splice (static ::$ g_coroutine_array ,$ idx ,1 );
2290
- }
2274
+ public static function coroutinesLoopController ($ hash_key ,$ data ){
2275
+
2276
+
2277
+ $ it = static ::$ g_coroutine_array [$ hash_key ];
2278
+ if ($ it ->valid ()){
2279
+ $ _hash_key = $ it ->send ($ data );
2280
+ static ::$ g_coroutine_array [$ _hash_key ]=$ it ;
2291
2281
}
2292
- $ idx --;
2282
+ unset(static ::$ g_coroutine_array [$ hash_key ]);
2283
+ }
2284
+ public static function generateCoroutineHashKey (){
2285
+ static $ idx = 0 ;
2286
+ return md5 (time ()."_ " .(++$ idx ));
2293
2287
}
2294
2288
}
0 commit comments