phpÖйØÓÚfsockopenµÄÏà¹ØËæ±Ê
ÔÎÄ£ºhttp://www.cnblogs.com/mxw09/archive/2011/12/30/2307019.html
²âÊÔ»·¾³£¬´Ó±¾»ú£¨windows£©·ÃÎÊÄÚÍâһ̨linux·þÎñÆ÷£¨´Ë·þÎñÆ÷×°µÄÊÇnginx£©
·þÎñÆ÷ÉϵÄindex.phpÈçÏ£º
<?php echo 1; ?>
1.ʹÓÃHttp1.1ÐÒéÇëÇó
function asyn_sendmail() { $ip = '192.168.1.45'; $url = '/index.php'; $fp = fsockopen($ip, 80, $errno, $errstr, 5); if (!$fp) { echo "$errstr ($errno)<br />\n"; } $end = "\r\n"; $input = "GET $url HTTP/1.1$end"; //Èç¹û²»¼ÓÏÂÃæÕâÒ»¾ä,»á·µ»ØÒ»¸öhttp400´íÎó //$input.="Host: $ip$end"; //Èç¹û²»¼ÓÏÂÃæÕâÒ»¾ä,ÇëÇó»á×èÈûºÜ¾Ã //$input.="Connection: Close$end"; $input.="$end"; fputs($fp, $input); $html = ''; while (!feof($fp)) { $html.=fgets($fp); } fclose($fp); writelog($html); echo $html; } function writelog($message) { $path = 'D:\log.txt'; $handler = fopen($path, 'w+b'); if ($handler) { $success = fwrite($handler, $message); fclose($handler); } } asyn_sendmail();
Èç¹û×¢ÊÍÁË$input.="Host: $ip$end";ÕâÒ»¾ä£¬Ôò»áµÃµ½Ò»¸ö404´íÎó£¬D:\log.txtÄÚÈÝÈçÏ£º
HTTP/1.1 400 Bad Request Server: nginx/0.8.46 Date: Fri, 30 Dec 2011 02:11:45 GMT Content-Type: text/html Content-Length: 173 Connection: close <html> <head><title>400 Bad Request</title></head> <body bgcolor="white"> <center><h1>400 Bad Request</h1></center> <hr><center>nginx/0.8.46</center> </body> </html>
˵Ã÷ʹÓÃhttp1.1Á¬½Ó£¬Ôò±ØÐë¼ÓÉÏHostÇëÇó±íÍ·
Èç¹û¼ÓÉÏÁËûÓÐ×¢ÊÍ$input.="Host: $ip$end";ÕâÒ»¾ä £¬ÔòÇëÇó³É¹¦£¬D:\log.txtÄÚÈÝÈçÏ£º
HTTP/1.1 200 OK Server: nginx/0.8.46 Date: Fri, 30 Dec 2011 02:20:49 GMT Content-Type: text/html Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding X-Powered-By: PHP/5.3.8 1 0 0
·µ»Ø³É¹¦£¬µ«ÊDz»Ã÷°×Ϊʲô·þÎñÆ÷·µ»ØÄÚÈݶàÁË2¸ö0(ºóÀ´ÍøÉϲéѯ×ÊÁÏ·¢ÏÖ£¬ÕâÊÇÒòΪ·þÎñÆ÷ʹÓÃÁËchunkedÊä³öËùÖ£¬ÓÃWireshark×¥°ü¿ÉÇåÎú¿´µ½Æäϸ½Ú)¡£Èç¹û²»¼Ó$input.="Connection: Close$end";ÕâÒ»¾ä £¬ÔòHttpÇëÇó»á×èÈûºÜ¾Ã(ÔÚÕâÒ»¾äfgets($fp)×èÈû)
2.²»Ö¸¶¨Http°æ±¾
<?php
function asyn_sendmail() {
$ip = '192.168.1.45';
$url = '/servertimmer/inserttopicshow/13990/AA8AB76B-7280-578F-12F2-F423685FBD26';
$fp = fsockopen($ip, 80, $errno, $errstr, 5);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
}
$end = "\r\n";
$input = "GET $url$end";
$input.="$end";
fputs($fp, $input);
$html = '';
while (!feof($fp)) {
$html.=fgets($fp);
}
fclose($fp);
writelog($html);
echo $html;
}
function writelog($message) {
$path = 'D:\log.txt';
$handler = fopen($path, 'w+b');
if ($handler) {
$success = fwrite($handler, $message);
fclose($handler);
}
}
asyn_sendmail();
?>
ÇëÇóÁ¢¿Ì·µ»Ø£¬Ã»ÓÐ×èÈû£¬·µ»ØÄÚÈÝÈçÏ£º
1
×¢Ò⣬·µ»ØÄÚÈÝÖÐûÓÐhttp±êÍ·£¬ÇÒûÓб»×èÈû¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ