demo.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. define('CONFIG_FILE', __DIR__ . '/config.php');
  3. include __DIR__ . '/functions.php';
  4. include __DIR__ . '/class.async.php';
  5. $cfg = [];
  6. load_config();
  7. // ---- 实际的业务代码 ----
  8. $send = empty($_GET['send']) ? 'redis' : $_GET['send'];
  9. VIEW(['ext' => get_loaded_extensions()]);
  10. // ---- 发起异步任务 ----
  11. switch ($send) {
  12. case 'udp': //使用UDP
  13. $s = stream_socket_client("udp://{$cfg['udp_host']}:{$cfg['udp_port']}", $errno, $error);
  14. if ($s) {
  15. $flag = fwrite($s, json_encode(array_merge(['test'], $_GET)));
  16. fclose($s);
  17. }
  18. break;
  19. case 'sysvmsg': //使用SYSVMSG
  20. $q = msg_get_queue($cfg['sysvmsg_key'], 0666);
  21. if ($q) {
  22. msg_send($q, 1, json_encode(array_merge(['test'], $_GET)), false, false);
  23. }
  24. break;
  25. default: //直接使用Redis-Cli
  26. $async = new Async($cfg['redis_host'], $cfg['redis_port'], $cfg['worker_num']);
  27. $async->pushJob(array_merge(['test'], $_GET));
  28. break;
  29. }
  30. // ---- 其它函数 ----
  31. function VIEW($data) { ?>
  32. <!doctype html>
  33. <html>
  34. <head>
  35. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  36. <title>扩展列表</title>
  37. </head>
  38. <body>
  39. <h1>扩展列表</h1>
  40. <ul>
  41. <?php foreach ($data['ext'] as $item) { ?>
  42. <li><?php echo $item; ?></li>
  43. <?php } ?>
  44. </ul>
  45. </body>
  46. </html>
  47. <?php
  48. }