ÌÔ±¦Ð£ÕжþÃæPHP ±¯¾ç£º
ÎÊÌâÒ»£ºÐÂÀË΢²©Ê×Ò³ ÄãºÍËû¹²Í¬¹Ø×¢µÄÈË ¹¦ÄÜʵÏÖ£¬ÓÃÓÚ´æ´¢ÈËÕâ¸öÐÅÏ¢µÄ·½·¨ÊÇʲô£¿
1.¿ÉÒÔʹÓÃredisµÄset·½Ê½´æ´¢£¬Ê¹ÓÃsinterÃüÁî·µ»Ø½»¼¯¡£
2.¿ÉÒÔʹÓÃPHPµÄarray_intersectº¯ÊýʵÏÖ¡£
ÎÊÌâ¶þ£ºPHP¾²Ì¬ÀàµÄÌØÐÔ£¿
´ð£º1¡¢±»ÉùÃ÷Ϊ¾²Ì¬ÀàµÄÀ಻ÔÊÐí°üº¬ÈκηǾ²Ì¬³ÉÔ±
2¡¢³éÏó¾²Ì¬ÀàÖеľ²Ì¬·½·¨²»ÔÊÐíµ÷Óã¬Ëü±ØÐëÏȱ»¼Ì³Ð¡£
3¡¢ÔÚ¾²Ì¬ÀàÖУ¬ÔÊÐí³éÏóµÄ¾²Ì¬·½·¨¡£
4¡¢¾²Ì¬À಻ÔÊÐíº¬ÓÐ ¹¹Ô캯Êý¡¢Îö¹¹º¯Êý¡¢¶¯Ì¬À¹½Øº¯ÊýÒÔ¼° __toString()¡£
5¡¢¾²Ì¬À಻ÔÊÐí¼Ì³Ð×ԷǾ²Ì¬Àà¡£
6¡¢ÎªÁËÏòϼæÈÝ£¬Ä¿Ç°º¬Óо²Ì¬³ÉÔ±µÄ³éÏóÀà/·Ç¾²Ì¬ÀàµÄÐÐΪ²»»á±»¸Ä±ä¡£
7¡¢ÔÚ³éÏóÀàÖÐÌí¼Ó __setStatic() ÒÔ¼° __getStatic() ÒÔ´úÌæ __get() ¡¢ __set()¡£
8¡¢¾²Ì¬À಻Äܱ»ÊµÀý»¯
9¡¢¾²Ì¬Àà¿ÉÒÔʵÏÖ×ÔÖ»°üº¬¾²Ì¬·½·¨µÄ½Ó¿Ú
ɨ䣺Ëùν¾²Ì¬ÀàÖ¸µÄÊÇÎÞÐèʵÀý»¯³É¶ÔÏó£¬Ö±½Óͨ¹ý¾²Ì¬·½Ê½µ÷ÓõÄÀà¡£´úÂëÈçÏ£º
class Math { public static function ceil($value) { return ceil($value); } public static function floor($value) { return floor($value); } }
´ËʱÀàËù°çÑݵĽÇÉ«¸üÏñÊÇÃüÃû¿Õ¼ä£¬Õâ»òÐíÊǺܶàÈËϲ»¶Ê¹Óþ²Ì¬Àà×îÖ±½ÓµÄÔÒò¡£
ÎÊÌâÈý£ºÓÃPHPÒÔ¼°shellºÍperlд³ö´Óaccess_logÖвéÕÒ³ö³öÏÖ×î¶àµÄIPµÄ·½·¨¡£
PHP´úÂëÈçÏ£º
1 function new_sort($a,$b){ 2 if ($a == $b) return 0; 3 return ($a>$b) ?-1:1; 4 } 5 $pattern='/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/'; 6 if($file = file_get_contents("/var/log/httpd/access_log")) 7 { 8 if(preg_match_all($pattern, $file, $matches)) 9 {10 $result = array_count_vaules($matches[0]);11 uasort($result,"new_sort");12 print_r($result);13 }else{echo "match failed!"}14 }else{echo "open file failed!!"}
Perl´úÂëÈçÏ£º
#!/usr/bin/perl -w open(ACCESS,'/var/log/httpd/access_log');@log =;foreach $word (@log){ $word =~ /d{1,3}.d{1,3}.d{1,3}.d{1,3}/; $match = $&; $matchlist{$match} +=1; }@sorted = map {{($_=>$matchlist{$_})}} sort {$matchlist{$a} cmp $match{$b} or $a cmp $b} keys %matchlist;foreach $cap (keys(%matchlist)){ ($key,$value) = each %$cap; print("$key => $valuen"); }close(ACCESS);
Ö±½ÓÃüÁîʵÏÖ£º
awk -F' ' '{print $1}' /var/log/httpd/access_log | uniq -c | sort -nr
ÎÊÌâËÄ£ºPHP»ñÈ¡ÍøÒ³ÄÚÈݵķ½·¨¡£
1.file_get_contents: ½«Õû¸öÎļþ¶ÁÈëÒ»¸ö×Ö·û´®¡£
2.Curl:Á÷³ÌΪcurl_init();curl_setopt();curl_exec();curl_close();
<!--?php $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); //ÔÚÐèÒªÓû§¼ì²âµÄÍøÒ³ÀïÐèÒªÔö¼ÓÏÂÃæÁ½ÐÐ //curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); //curl_setopt($ch, CURLOPT_USERPWD, US_NAME.":".US_PWD); $contents = curl_exec($ch); curl_close($ch); echo $contents;
3.fopen->fread->fclose:ʵÏÖÀàËÆfile_get_contents,ͨ¹ý´ò¿ªÔ¶³ÌÎļþ²¢¶ÁÈ¡¡£
ÆäÖÐ fopenºÍfile_get_contentsÐèÒª¿ªÆôphp.iniÖеÄallow_url_fopenÑ¡ÏCurlÐèÒª¿ªÆôcurlÑ¡Ïî¡£
4.¾rtxbcÌáÐÑ£¬ÖªµÀÁËÆäʵ³£ÓõÄÊÇsocket·½·¨×¥È¡ÍøÒ³ÄÚÈÝ¡£
ÕÒµ½ÁËÒ»¶ÎʾÀý´úÂëÈçÏ£º
function get_content_by_socket($url, $host){ $fp = fsockopen($host, 80) or die("Open ". $url ." failed"); $header = "GET /".$url ." HTTP/1.1rn"; $header .= "Accept: */*rn"; $header .= "Accept-Language: zh-cnrn"; $header .= "Accept-Encoding: gzip, deflatern"; $header .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; InfoPath.1; .NET CLR 2.0.50727)rn"; $header .= "Host: ". $host ."rn"; $header .= "Connection: Keep-Alivern"; //$header .= "Cookie: cnzz02=2; rtime=1; ltime=1148456424859; cnzz_eid=56601755-rnrn"; $header .= "Connection: Closernrn"; fwrite($fp, $header); while (!feof($fp)) { $contents .= fgets($fp, 8192); } fclose($fp); return $contents; }
ÎÊÌâÎ壺MemcacheºÍmemcachedµÄÇø±ð£¬»º´æµÄʱ¼äÓ¦¸ÃÔõôÉèÖã¿
memcachedÖÐÓÐgetmultiºÍsetmulti£¬ºÜʵÓ㬶øÇÒ»¹Óкܶ෽·¨ÊÇmemcacheûÓеģ¬Òò´Ë¿ÉÒÔÀí½âΪmemcacheµÄÉý¼¶°æ¡£
ÎÊÌâÁù£ºRedisÓÐÄÄЩ´æ´¢ÀàÐÍ£¬¸÷ÓÐʲôÌص㡣
¾ßÌåÀàÐÍ°üÀ¨strings, list, set, sorted set, hash¡£
http://www.cnblogs.com/bigdog/archive/2011/09/24/2189612.html
ÎÊÌâÆߣºNode.jsµÄÌØÐÔ£¬Ê²Ã´ÊÇÒì²½£¿
Òì²½£¬Ê¼þÇý¶¯£¬·Ç×èÈû¡£
Òì²½µÄÌصã¾ÍÊÇÒ»¸öµ÷ÓÃÕß·¢³öÒ»¸öÇëÇóÖ®ºó²»ÐèÒªÂíÉϵõ½½á¹û£¬¶øÊǵȴý´¦ÀíÕߵóö½á¹û¼¯Ö®ºó·µ»Ø¸øµ÷ÓÃÕߣ¬ºÍͬ²½µÄÄã˵ÍêÎÒÔÙ˵¸ÅÄͬ¡£
ʼþÇý¶¯ÊÇjavascriptµÄÌØÐÔ£¬µ±Ò»¸ö¶¯×÷´¥·¢Ö®ºóÇý¶¯Ò»¸öʼþ£¬¿ÉÒÔÊǶà¶Ô¶àµÄ¹Øϵ£¬Ò²¾ÍÊÇ˵¶à¸ö¶¯×÷Çý¶¯¶à¸öʼþ¡£
·Ç×èÈûÊÇnode.jsµÄÒ»¸öÐÂÌØÐÔ£¬´«Í³±à³ÌÓïÑÔÊÇÃæÏò¹ý³ÌµÄÁ÷³Ì£¬Ò²¾ÍÊÇÉÏÃæµÄ²Ù×÷ûÍê³É£¬ÏÂÃæµÄ²Ù×÷»á×èÈûÔÚÄÇÀïµÈ´ý²Ù×÷Íê³É¡£¶ønode.jsµÄÌصã¾ÍÊÇ·Ç×èÈû£¬ÓÃÏÂÃæµÄÀý×ÓÀ´ËµÃ÷£º
$file = fopen("/etc/file",r+);$contents = fread($file,filesize("/etc/file"));fclose();echo "this will not display";
Îļþ¶ÁдûÍê³ÉµÄʱºò£¬echo²»»áÊä³ö£¬µ«ÊÇÔÚnode.jsµÄÌØÐÔÖоͲ»Ò»ÑùÁË£¬¿´ÏÂÃæµÄ´úÂ룺
require("fs") fs.readFile('/etc/filename','UTF-8',function(err,date){ if(err) throw err; console.log(date); }); console.log("running");
Õâ¸ö³ÌÐòÖУ¬¶ÁÈ¡ÎļþµÄ²Ù×÷ûÓÐÓ°Ïìconsole.logÊä³örunning£¬¶ødateÐèÒªÎļþ¶ÁÈ¡Íê±ÏÔÙÊä³ö£¬Á½Õß²»×èÈû¡£
´ó½ÖÍøÉÏ¿´µ½µÄÐÂÀËPHPÃæÊÔÌâ
1¡¢cookie¡¢sessionµÄÁªÏµºÍÇø±ð£¬¶ą̀web·þÎñÆ÷ÈçºÎ¹²Ïísession£¿
cookieÔÚ¿Í»§¶Ë±£´æ״̬£¬sessionÔÚ·þÎñÆ÷¶Ë±£´æ״̬¡£µ«ÊÇÓÉÓÚÔÚ·þÎñÆ÷¶Ë±£´æ״̬µÄʱºò£¬ÔÚ¿Í»§¶ËÒ²ÐèÒªÒ»¸ö±êʶ£¬ËùÒÔsessionÒ²¿ÉÄÜÒª½èÖúcookieÀ´ÊµÏÖ±£´æ±êʶλµÄ×÷Óá£
cookie°üÀ¨Ãû×Ö£¬Öµ£¬Óò£¬Â·¾¶£¬¹ýÆÚʱ¼ä¡£Â·¾¶ºÍÓò¹¹³ÉcookieµÄ×÷Ó÷¶Î§¡£cookieÈç¹û²»ÉèÖùýÆÚʱ¼ä£¬ÔòÕâ¸öcookieÔÚä¯ÀÀÆ÷½ø³Ì´æÔÚʱÓÐЧ£¬¹Ø±ÕʱÏú»Ù¡£Èç¹ûÉèÖÃÁ˹ýÆÚʱ¼ä£¬Ôòcookie´æ´¢ÔÚ±¾µØÓ²ÅÌÉÏ£¬ÔÚ¸÷ä¯ÀÀÆ÷½ø³Ì¼ä¿ÉÒÔ¹²Ïí¡£
session´æ´¢ÔÚ·þÎñÆ÷¶Ë£¬·þÎñÆ÷ÓÃÒ»ÖÖÉ¢ÁбíÀàÐ͵Ľṹ´æ´¢ÐÅÏ¢¡£µ±Ò»¸öÁ¬½Ó½¨Á¢µÄʱºò£¬·þÎñÆ÷Ê×ÏÈËÑË÷ÓÐûÓд洢µÄsession id£¬Èç¹ûûÓУ¬Ôò½¨Á¢Ò»¸öеÄsession£¬½«session id·µ»Ø¸ø¿Í»§¶Ë£¬¿Í»§¶Ë¿ÉÒÔÑ¡ÔñʹÓÃcookieÀ´´æ´¢session id¡£Ò²¿ÉÒÔÓÃÆäËûµÄ·½·¨£¬±ÈÈç·þÎñÆ÷¶Ë½«session id¸½ÔÚURLÉÏ¡£
Çø±ð£º
(1).cookieÔÚ±¾µØ£¬sessionÔÚ·þÎñÆ÷¶Ë¡£
(2).cookie²»°²È«£¬ÈÝÒ×±»ÆÛÆ£¬sessionÏà¶Ô°²È«¡£
(3).sessionÔÚ·þÎñÆ÷¶Ë£¬·ÃÎʶàÁË»áÓ°Ïì·þÎñÆ÷ÐÔÄÜ¡£
(4). cookieÓдóСÏÞÖÆ£¬Îª3K
¶à·þÎñÆ÷¹²Ïísession¿ÉÒÔ³¢ÊÔ½«session´æ´¢ÔÚmemcacheÖС£
2¡¢httpÐÒéÖеÄpostºÍgetÓкÎÇø±ð£¿
GETÓÃÓÚ»ñÈ¡ÐÅÏ¢£¬²»Ó¦¸ÃÓÃÓÚÐÞ¸ÄÐÅÏ¢£¬POST¿ÉÓÃÓÚ¸üÐÂÐÞ¸ÄÐÅÏ¢¡£
GET¿É´«ÊäÊý¾Ý´óСºÍURLÓйأ¬¶øPOSTûÓÐÏÞ¶¨´óС£¬´óСºÍ·þÎñÆ÷ÅäÖÃÓйء£
GET·ÅÔÚURLÖУ¬Òò´Ë²»°²È«£¬¶øPOST´«ÊäÊý¾Ý¶ÔÓÚÓû§À´ËµÊDz»¿É¼ûµÄ£¬ËùÒÔÏà¶Ô°²È«¡£
¾@ÊéºÃ ´ó´óÌáÐÑ£¬Çø±ð»¹ÓУº
ÔÚajax: post²»±»»º´æ£¬get±»»º´æËùÒÔÒ»°ãÔÚÇëÇó½áβ¼ÓMath.random();
SERVER¶Ë½ÓÊÜ:ÒòΪÔÚsubmitÌá½»µÄʱºòÊÇ°´²»Í¬·½Ê½½øÐбàÂëµÄ£¬ËùÒÔ·þÎñ¶ËÔÚ½ÓÊܵÄʱºò»á°´ÕÕ²»Í¬µÄ·½Ê½½øÐнÓÊÜ!
±àÂ뷽ʽ:Èç¹û´«µÝÊý¾ÝÊÇ·Ç-ASCII,ÄÇôGETÒ»°ãÊDz»ÊÊÓ¦µÄ£¬ËùÒÔÔÚ´«µÝµÄʱºò»á×ö±àÂë´¦Àí!
3¡¢reqiureµÄinclude¶¼¿É°üº¬Îļþ£¬¶þÕßµÄÇø±ðºÎÔÚ£¿
requireÔÚ°üº¬Îļþ³ö´íÖ®ºó·µ»ØÖÂÃü´íÎó£¬Ìø³öÔËÐУ¬¶øinclude ÔÚ°üº¬Îļþ³ö´íÖ®ºó·µ»Ø¾¯¸æÐÅÏ¢£¬¼ÌÐøÔËÐС£
4¡¢phpÖÐwebÉÏ´«ÎļþµÄÔÀíÊÇʲô£¬ÈçºÎÏÞÖÆÉÏ´«ÎļþµÄ´óС£¿
PHPÉÏ´«ÎļþĬÈÏ´óСΪ2M£¬ÉèÖÃÉÏ´«´óСµÄÅäÖÃÏîÊÇupload_max_filesize,post_max_sizeÉèÖÃÒ»´ÎPOSTÖÐPHPÄܽÓÊÕµÄ×î´óÊý¾ÝÁ¿£¬Ó¦¸Ã±Èupload_max_filesize´ó¡£
5¡¢Ð´Ò»¸öº¯Êý£¬¿ÉÒÔ±éÀúÎļþ¼ÐϵÄËùÓÐÎļþºÍÎļþ¼Ð¡£
¡¡¡¡²»ÖªµÀÎÒµÄÀí½âÊDz»ÊDz»¶Ô£¬Èç¹ûÊǼòµ¥µÄÁгöÎļþºÍÎļþ¼ÐµÄ»°£¬ÏÂÃæÁ½¸öÓ¦¸Ã¿ÉÒÔ¡£±¾ÈËˮƽ²Ë£¬Ã»·¢ÏÖʲôÏÝÚå..¿¼ÂÇÁËһϣ¬»á²»»áÌâÄ¿ÊÇÒªÇó×öÒ»¸ö±éÀú£¬°Ñ×ÓÎļþ¼ÐϵÄÎļþ¶¼ÒªÏÔʾ³öÀ´£¬ÕâÑùµÄ»°ÐèҪʹÓõݹé¶ÔÎļþ¼Ð½øÐÐÏÔʾ¡£¶Ôÿ´Îscandir³öÀ´µÄÌõÄ¿½øÐÐis_dirÅжϣ¬ÊÇdir µÄ»°µÝ¹é½øÐÐÏÂÒ»ÂÖµÄscandir¡£
1 function bianli($dir) 2 { 3 if(is_dir($dir)) 4 { 5 $output = scandir($dir); 6 print_r($output); 7 } 8 } 9 10 function bianli2($dir)11 {12 if(is_dir($dir)){13 $command = "ls -a $dir";14 $ret = `$command`;15 $pattern = "/S+/";16 if(preg_match_all($pattern,$ret,$matches))17 {18 print_r($matches);19 }20 }21 }
6¡¢ÓÐmail.logµÄÒ»¸öÎĵµ£¬ÄÚÈÝΪÈô¸ÉÓʼþµØÖ·£¬ÆäÖÐÓÃ'n'½«ÓʼþµØÖ··Ö¸ô¡£ÒªÇó´ÓÖÐÌôÑ¡³ösina.comµÄÓʼþµØÖ·£¨°üÀ¨´ÓÎļþ¶ÁÈ¡¡¢¹ýÂ˵½ÁÐÓ¡³öÀ´£©¡£
1 $mail = file_get_contents('mail.log');2 $pattern = "/S+sina.com/";3 $rpattern = "/\n/";4 preg_filter($rpattern,"",$mail);5 if(preg_match_all($pattern,$mail,$matches))6 {7 print_r($matches);8 }
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿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¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ