|
11 | 11 | }
|
12 | 12 |
|
13 | 13 | require_once ("config.inc.php");
|
14 |
| -require_once('lib/memqueue.php'); |
15 | 14 | ini_set("memory_limit", "512M");
|
16 | 15 | ini_set("max_execution_time", "3600");
|
17 | 16 | ignore_user_abort(true);
|
|
221 | 220 | );
|
222 | 221 | msglog($cmd_param);
|
223 | 222 |
|
| 223 | +// check api/made.php |
224 | 224 | // uid limit r_flag xx yy shiftx shifty datum version outx outy title outimage ip channel
|
225 | 225 | $add_param_array=[ $MYUID, $user['limit'], $recreate_flag, $xx, $yy, $shiftx, $shifty, isset($inp['97datum'])? "97":"67",$version, $outx, $outy, $title,$outimage, $_SERVER['REMOTE_ADDR'],$log_channel ];
|
226 | 226 | // ouch forget to consider ipv6 addr
|
227 | 227 | $add_param_str=json_encode($add_param_array);
|
228 | 228 |
|
229 | 229 | memcached_set($log_channel, $add_param_str);
|
230 | 230 |
|
| 231 | + |
| 232 | +use xobotyi\beansclient\Client as beansclient; |
| 233 | +use xobotyi\beansclient\Socket\SocketsSocket as beansconnect; |
| 234 | + |
231 | 235 | if (isset($CONFIG['use_queue']) && $CONFIG['use_queue'] == true){
|
232 |
| - $workload = $cmd_param; |
233 |
| - $mq = new Memqueue("localhost",11211); |
234 |
| - $id = $mq->push("mqq_make_map",$workload); |
235 |
| - |
236 |
| - while(!$mq->is_processed('mqq_make_map',$id)) { |
| 236 | + // 使用 beanstalkd 請 config.inc.php 中加上相關參數 |
| 237 | + $sock = new beansconnect(host: $CONFIG['beanstalk_server'], port: $CONFIG['beanstalk_port'], connectionTimeout: 2); |
| 238 | + $client = new beansclient(socket: $sock, defaultTube: $CONFIG['beanstalk_tube'], defaultTTR: 3600); |
| 239 | + $job = $client->put($cmd_param); |
| 240 | + while(1){ |
| 241 | + $st = $client->statsJob($job['id']); |
| 242 | + if (is_null($st) || $st['state'] == 'reserved') { |
| 243 | + notify_web($log_channel,array('worker is working...')); |
| 244 | + $sock->disconnect(); |
| 245 | + exit(0); |
| 246 | + } |
| 247 | + notify_web($log_channel,array("waiting for a worker ")); |
237 | 248 | sleep(2);
|
238 |
| - notify_web($log_channel,array("waiting for queue worker ")); |
239 | 249 | }
|
240 |
| - notify_web($log_channel,array('worker is working...')); |
241 |
| - |
| 250 | + |
242 | 251 | } else {
|
| 252 | + // 前端可能無法等太久 |
243 | 253 | exec("php cmd_make2.php ".$cmd_param, $output, $ret);
|
244 | 254 | if ($ret != 0) {
|
245 | 255 | foreach ($output as $line) {
|
|
0 commit comments