jquery tab

$(document).ready(function () {

        $("#tabs li").bind("click", function () {

            var index = $(this).index();

            var divs = $(".nav_box");

            $(this).parent().children("li").attr("class", "");//将所有选项置为未选中
            $(this).attr("class", "current"); //设置当前选中项为选中样式
            
            divs.hide();//隐藏所有选中项内容

            divs.eq(index).show(); //显示选中项对应内容

        });

  

});

curl_multi*

<?php
        // While we're still active, execute curl
        $active = null;
        do {
            $mrc = curl_multi_exec($multi, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    
        while ($active && $mrc == CURLM_OK) {
            // Wait for activity on any curl-connection
            if (curl_multi_select($multi) == -1) {
                usleep(1);
            }
    
            // Continue to exec until curl is ready to
            // give us more data
            do {
                $mrc = curl_multi_exec($multi, $active);
            } while ($mrc == CURLM_CALL_MULTI_PERFORM);
        }
function classic_curl($urls, $delay) 
{
    $queue = curl_multi_init();
    $map = array();

    foreach ($urls as $url) 
    {
        // create cURL resources
        $ch = curl_init();

        // 设置 URL 和 其他参数
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_NOSIGNAL, true);

        // 把当前 curl resources 加入到 curl_multi_init 队列
        curl_multi_add_handle($queue, $ch);
        $map[$url] = $ch;
    }

    $active = null;

    // execute the handles
    do {
        $mrc = curl_multi_exec($queue, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);

    while ($active > 0 && $mrc == CURLM_OK) {
        while (curl_multi_exec($queue, $active) === CURLM_CALL_MULTI_PERFORM);
        // 这里 curl_multi_select 一直返回 -1,所以这里就死循环了,CPU就100%了
        if (curl_multi_select($queue, 0.5) != -1) 
        {
            do {
                $mrc = curl_multi_exec($queue, $active);
            } while ($mrc == CURLM_CALL_MULTI_PERFORM);
        }
    }

    $responses = array();
    foreach ($map as $url=>$ch) {
        //$responses[$url] = callback(curl_multi_getcontent($ch), $delay);
        $responses[$url] = callback(curl_multi_getcontent($ch), $delay, $url);
        curl_multi_remove_handle($queue, $ch);
        curl_close($ch);
    }

    curl_multi_close($queue);
    return $responses;
}

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;

https 证书检测

需要对多台机器https证书进行检测。因此需要通过ip进行请求。
原方法:

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
            curl_exec($ch);

这种请求方式无法做到检测https证书;
采用下面的方法:
http://stackoverflow.com/questions/24351152/how-to-manually-resolve-hosts-in-https-connections-in-php

https://curl.haxx.se/libcurl/c/CURLOPT_RESOLVE.html
需用到php版本比较新,因此升级到php5.6.28,另libcurl版本也较低,升级到7.50.0,同时需要支持https;

重新编译php,升级curl

查找php编译参数
/usr/local/php/bin/php -i |grep configure

修改参数:

–with-curl=/usr/local/curl

make

make install

重启php-fpm即可;

新代码如下:

     
$ip='xx.xx.xx.20';

$url='https://xx.com';
$port=443;

$hostname='';
$resolve= array(sprintf(
    "%s:%d:%s", 
    $hostname,
    $port,
    $ip
));

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RESOLVE, $resolve);
curl_setopt($ch, CURLOPT_VERBOSE,true);
curl_setopt($ch, CURLOPT_STDERR,fopen('01.log','w'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO,  'E:/ca-bundle.crt'); 
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);


$response = curl_exec($ch);
echo $response;
$error=curl_error($ch);
echo $error;

结果如下:

* Added xx.com:443:xx.xx.xx.20 to DNS cache
* Rebuilt URL to: https://xx.com/
* Hostname xx.com was found in DNS cache
* Trying xx.xx.xx.20…
* Connected to xx.com (xx.xx.xx.20) port 443 (#0)

可以看到请求到指定的ip上。其他信息如证书过期时间,证书是否匹配也会输出的log文件。

可能错误信息:
SSL: no alternative certificate subject name matches target host name ‘xx.xx.com’

可以调整系统时间测试证书过期情况。