海运的博客

PHP异步执行

发布时间:December 31, 2013 // 分类:PHP // No Comments

<?php
   $start = microtime(true); 
   $fp=fsockopen('localhost',80,$errno,$errstr,5);
   if(!$fp){
      echo "$errstr ($errno)<br />\n";
   }
   $head = "GET /get.php HTTP/1.1 \r\n";
   $head .= "Host: localhost \r\n";
   $head .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0 \r\n";
   $head .= "Connection: Close \r\n\r\n";
   //发送请求
   fputs($fp,$head);
   /* 忽略结果
   while(!feof($fp)) {
      echo fgets($fp,128);
   }
   */
   fclose($fp);
   header("Content-Type: text/html;charset=utf-8");
   $end = microtime(true); 
   echo "脚本执行时间".($end - $start).'<br>';  
?>

异步执行的代码:

<?php
   ignore_user_abort(1); //由于异步请求后会立即断开连接,默认会终止脚本,忽略掉
   set_time_limit(0); //取消脚本执行延时上限
   for ($i = 1; $i < 10; $i++)
   {
      $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, "https://www.haiyun.me/?$i");
      curl_setopt($ch, CURLOPT_REFERER, "http://www.test.com");
      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0");
      curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,3);
      curl_setopt($ch,CURLOPT_TIMEOUT,3);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
      curl_exec($ch);
   }
?>

PHP查看脚本占用内存

发布时间:December 31, 2013 // 分类:PHP // No Comments

<?php
   function convert($size)
   {
      $unit=array('b','kb','mb','gb','tb','pb');
      return @round($size/pow(1024,($i=floor(log($size,1024)))),2).$unit[$i];
   }

   echo convert(memory_get_usage(true)); 
?>

PHP静态调用非静态方法性能

发布时间:December 30, 2013 // 分类:PHP // No Comments

============Which method========================Time======
Inline calculation                             0.0805 s
Normal function call                           0.3438 s
Normal method called through object            0.4118 s
Static method called statically                0.4280 s
Unspecified method called through object()     0.4294 s
Unspecified method called statically()         0.6960 s

来源:http://bbs.csdn.net/topics/350118147

PHP正则验证邮箱及域名MX

发布时间:December 27, 2013 // 分类:PHP // No Comments

<?php
   function validate_email($email){

      $exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";

      if(eregi($exp,$email)){

         if(checkdnsrr(array_pop(explode("@",$email)),"MX")){
            return true;
         }else{
            return false;
         }

      }else{

         return false;

      }   
   }

   echo validate_email('qq@qq.com');
?>

PHP5.5编译参数

发布时间:December 27, 2013 // 分类:PHP // No Comments

yum install gcc autoconf libxml2-devel openssl-devel curl-devel libmcrypt-devel
./configure --prefix=/usr/local/php \
--with-config-file-path=/etc/php \
--enable-fpm \
--enable-pcntl \
--enable-mysqlnd \
--enable-opcache \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem  \
--enable-sysvshm \
--enable-shmop \
--enable-zip \
--enable-ftp \
--enable-soap \
--enable-xml \
--enable-mbstring \
--disable-rpath \
--disable-debug \
--disable-fileinfo \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-pcre-regex \
--with-iconv \
--with-zlib \
--with-mcrypt \
--with-gd \
--with-openssl \
--with-mhash \
--with-xmlrpc \
--with-curl \
--with-imap-ssl
make
make install
分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...