Re: [請益] 關於伺服器的開啟或關閉狀態
※ 引述《taiwancat (月季)》之銘言:
: <?php
: $url = "www.kimo.com.tw";
: $socket = socket_create(AF_INET, SOCK_RAW, 1);
: socket_set_block($socket);
: socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO,
: array("sec"=>$timeout, "usec"=>0));
: if (@socket_connect($socket, $url, NULL))
: {
: die("Server $url is working!");
: } else {
: die("Server $url is down!");
: }
: ?>
我把他改成function
function check_server($url,$timeout=5){
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_set_block($socket);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>$timeout,
"usec"=>0));
$server_reply = (@socket_connect($socket, $url, NULL)) ? "運作中" : "停機中";
return $server_reply;
}
剛剛去看了一下官網 還蠻詳細的
http://tw.php.net/manual/en/ref.sockets.php
裡面有 ping 的 function 可以參考
--
********************************************************
* 瘋狂小惡魔分享討論區 *
* http://www.forum.Wu-Boy.com/index.php *
* 無名相簿-appleboy *
* http://www.wretch.cc/album/appleboy *
********************************************************
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.107.89
※ 編輯: appleboy46 來自: 140.123.107.89 (06/17 22:28)
推
06/21 05:02, , 1F
06/21 05:02, 1F
→
06/21 05:03, , 2F
06/21 05:03, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章
117
167