udp-cmd.php 492 B

12345678910111213141516171819202122232425
  1. <?php
  2. define('CONFIG_FILE', __DIR__ . '/config.php');
  3. include __DIR__ . '/functions.php';
  4. //检查参数
  5. if ($argc < 2) {
  6. die("Usage: {$argv[0]} CMD ARG...\n");
  7. }
  8. //加载配置
  9. $cfg = [];
  10. load_config();
  11. $s = stream_socket_client("udp://{$cfg['udp_host']}:{$cfg['udp_port']}", $errno, $error);
  12. if (!$s) {
  13. die("stream_socket_server() call failed: #{$errno},{$error}");
  14. }
  15. $args = $argv;
  16. array_shift($args); //php_self
  17. $flag = fwrite($s, json_encode($args));
  18. fclose($s);
  19. var_dump($flag);