12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- define('CONFIG_FILE', __DIR__ . '/config.php');
- include __DIR__ . '/functions.php';
- include __DIR__ . '/class.async.php';
- $cfg = [];
- load_config();
- // ---- 实际的业务代码 ----
- $send = empty($_GET['send']) ? 'redis' : $_GET['send'];
- VIEW(['ext' => get_loaded_extensions()]);
- // ---- 发起异步任务 ----
- switch ($send) {
- case 'udp': //使用UDP
- $s = stream_socket_client("udp://{$cfg['udp_host']}:{$cfg['udp_port']}", $errno, $error);
- if ($s) {
- $flag = fwrite($s, json_encode(array_merge(['test'], $_GET)));
- fclose($s);
- }
- break;
- case 'sysvmsg': //使用SYSVMSG
- $q = msg_get_queue($cfg['sysvmsg_key'], 0666);
- if ($q) {
- msg_send($q, 1, json_encode(array_merge(['test'], $_GET)), false, false);
- }
- break;
- default: //直接使用Redis-Cli
- $async = new Async($cfg['redis_host'], $cfg['redis_port'], $cfg['worker_num']);
- $async->pushJob(array_merge(['test'], $_GET));
- break;
- }
- // ---- 其它函数 ----
- function VIEW($data) { ?>
- <!doctype html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
- <title>扩展列表</title>
- </head>
- <body>
- <h1>扩展列表</h1>
- <ul>
- <?php foreach ($data['ext'] as $item) { ?>
- <li><?php echo $item; ?></li>
- <?php } ?>
- </ul>
- </body>
- </html>
- <?php
- }
|