이 함수를 cron 작업에서 실행하여 데이터베이스로 반환하는 데이터를 삽입하는 방법이 있습니까?이것을 cron으로 실행하려면 변환 하시겠습니까?
public function ping($host, $port=25565, $timeout=0.1) {
//Set up our socket
$beginning_time = microtime(true);
$fp = fsockopen($host, $port, $errno, $errstr, $timeout);
if (!$fp) return false;
$end_time = microtime(true);
//Send 0xFE: Server list ping
fwrite($fp, "\xFE");
//Read as much data as we can (max packet size: 241 bytes)
$d = fread($fp, 256);
//Check we've got a 0xFF Disconnect
if ($d[0] != "\xFF") return false;
//Remove the packet ident (0xFF) and the short containing the length of the string
$d = substr($d, 3);
//Decode UCS-2 string
$d = mb_convert_encoding($d, 'auto', 'UCS-2');
//Split into array
$d = explode("\xA7", $d);
//Return an associative array of values
return array(
'motd' => $d[0],
'players' => intval($d[1]),
'max_players' => intval($d[2]),
'latency' => ($end_time - $beginning_time) * 1000);
}
데이터가 반환되는 것은 끝에있는 배열입니다.
오류 ... 예. 함수를 호출하는 스크립트를 작성한 다음 PDO에서 리턴하는 데이터를 사용합니다. 그런 다음 스크립트를 호출 할 cron 작업을 설정합니다. – Quentin
저는 PHP와 물건에 익숙하지 않습니다. 정확히 어떻게해야할까요? – unlucky4ever
@ unlucky4ever - first 명령 줄에서 스크립트를 실행하고 원하는 효과를냅니다. 둘째, 'crontab'에 대한 매뉴얼 페이지를 찾는다. –