public function udp() { set_time_limit(0); $ip = '127.0.0.1'; $port = 9527; $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_bind($socket, $ip, $port); $mem = init_mem(); if ($mem == false) { return; } while (true) { socket_recvfrom($socket, $content, 1024, 0, $ip, $port); if (empty($content)) { continue; } //$this->log_data($content); $minute = (int) date("i"); $datagram = $mem->get('datagram'); if (empty($datagram)) { $datagram = array(); } $datagram[$minute][] = $content; $mem->set('datagram', $datagram); } socket_close($socket); $mem->close(); }
public function get_mem_data() { $mem = init_mem(); dump($mem->get('datagram')); }