MySQL wait_timeout

mysql wait_timeout 是指MySQL多久未收到请求,就关闭连接所用时间。

默认php 不需要调用mysql_close() 也会自己断开连接。

最近遇到一长时间运行程序,由于wait_timeout设置时间为10s 而此程序 每循环一次也sleep 10s ,程序未调用关闭MySQL,导致每次 MySQL都断开连接,因而产生大量close_wait连接。

主动关闭后,close_wait 不再产生。

 

http://blog.itpub.net/22664653/viewspace-2143671/

浅谈CLOSE_WAIT

nginx rewrite


location ~ "(product)\.php" {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/t_php/test_re/search$fastcgi_script_name;
include fastcgi_params;
}

location / {

rewrite "^/(.*)\/(\d{2})\.html" /product.php?action=product_detail&type=$1&product_id=$2 last;

}


访问 http://tool.yebanhei.com:8090/hh/10.html

打印$_GET 如下:

array(2) {
  ["type"]=>
  string(2) "hh"
  ["product_id"]=>
  string(2) "10"
}

 

 

MySQL 存储html页面或图片

MySQL

使用blob,可以避免同一页面中含有多个编码问题。

public function actionIndex()
	{
       
            $m_img = new Img();
            $url="http://news.qq.com/";
            $curl=curl_init($url);
            curl_setopt($curl, CURLOPT_FAILONERROR, true);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

            $info=curl_exec($curl);
            $curl_info=curl_getinfo($curl);
            //var_dump($curl_info);
            $content_type=$curl_info['content_type'];
            curl_close($curl);
            
	          $m_img->setAttributes(array(
	        							'img_url'=>$url,
                        'img_info'=>$info,
	        							));
	          $re = $m_img->save();



          
	}

    public function actionInfo()
    {
         $data=Mod::app()->db->createCommand()->select ('img_info')
                                              ->from('img')
                                              ->where('id=:id',array(':id'=>25))
                                              ->queryScalar();
        //Content-type 可根据curl_info获取
        header("Content-type: text/html; charset=GB2312" );                                        
        echo $data;
    }
CREATE TABLE `img` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `img_url` varchar(255) NOT NULL DEFAULT '',
  `img_info` mediumblob NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 COMMENT='img_store';

正则表达式

http://deerchao.net/tutorials/regex/regex.htm

<?php

preg_match_all("'<\s*a\s.*?href\s*=\s*	       # find <a href=
	       ([\"\'])?		       # find single or double quote
	       (?(1) (.*?)\\1 | ([^\s\>]+))    # if quote found, match up to next matching
					       # quote, otherwise match up to next space
	      'isx",$document,$links);

说明
.*?
懒惰限定符
(?(1) (.*?)\\1 | ([^\s\>]+))
(?(group)yes|no) 如果堆栈上存在以名为group的捕获内容的话,继续匹配yes部分的表达式,否则继续匹配no部分
[^\s\>]+

有时需要查找不属于某个能简单定义的字符类的字符。比如想查找除了数字以外,其它任意字符都行的情况,这时需要用到反义:
如:
[^x] 匹配除了x以外的任意字符
<a[^>]+>匹配用尖括号括起来的以a开头的字符串。

 

php-fpm Nginx 502 Bad Gateway – Permission denied

http://stackoverflow.com/questions/24325695/nginx-and-php-fpm-socket-owner

http://stackoverflow.com/questions/23598271/nginx-502-bad-gateway-permission-denied

php-fpm.conf 中
172 ; Set permissions for unix socket, if one is used. In Linux, read/write
173 ; permissions must be set in order to allow connections from a web server. Many
174 ; BSD-derived systems allow connections regardless of permissions.
175 ; Default Values: user and group are set as the running user
176 ; mode is set to 0660
177 listen.owner = nobody
178 listen.group = nobody
179 listen.mode = 0660

nginx.conf 中
user nobody nobody;