crontab php注意事项

lrenwang , 2013/01/22 19:27 , Linux , 评论(0) , 阅读(3080) , Via 本站原创

00 00 * * * cd /data/www/qhd5u && /usr/local/webserver/php5_2/bin/php /data/www/qhd5u/auto_server.php  


进入目录就没问题了 哈哈

正确的nginx重定向

lrenwang , 2013/01/18 15:03 , Linux , 评论(0) , 阅读(2695) , Via 本站原创
之前给nginx做301重定向的时候经常会这样写:

server {
    listen       80;
    server_name  www.qhd5u.com  qhd5u.com;
    if ($http_host = qhd5u.com) {
        rewrite  (.*)  http://www.qhd5u.com$1;
    }
    ...
}


实际应该

server {
    listen       80;
    server_name qhd5u.com;
    return       301 http://www.qhd5u.com$request_uri;
}

server {
    listen       80;
    server_name  www.qhd5u.com;
    ...
}

icon 2 png/gif/jpg class

lrenwang , 2012/12/19 14:50 , Php , 评论(0) , 阅读(3265) , Via 本站原创
网上找的资源,暂无验证

    /**
     * class.ico.php
     *
     **/  
  
    /**
     * Class Ico
     * Open ICO files and extract any size/depth to PNG format
     *
     * @version 0.1
     *
     * @method public  Ico($path = '')
     * @method public  LoadFile($path)
     * @method private LoadData($data)
     * @method public  TotalIcons()
     * @method public  GetIconInfo($index)
     * @method public  GetIcon($index)
     * @method private AllocateColor(&$im, $red, $green, $blue, $alpha = 0)
     **/  
    class Ico {  
        /**
         * Ico::bgcolor
         * Background color on icon extraction
         *
         * @type array(R, G, B) = array(255, 255, 255)
         * @var  public
         **/  
        var $bgcolor = array(255, 255, 255);  
        /**
         * Ico::bgcolor_transparent
         * Is background color transparent?
         *
         * @type boolean = false
         * @var  public
         **/  
        var $bgcolor_transparent = false;  
        /**
         * Ico::Ico()
         * Class constructor
         *
         * @param   optional    string   $path   Path to ICO file
         * @return              void
         **/  
        function Ico($path = '') {  
            if (strlen($path) > 0) {  
                $this->LoadFile($path);  
            }  
        }  
        /**
         * Ico::LoadFile()
         * Load an ICO file (don't need to call this is if fill the
         * parameter in the class constructor)
         *
         * @param   string   $path   Path to ICO file
         * @return  boolean          Success
         **/  
        function LoadFile($path) {  
         $this->_filename = $path;  
            if (($fp = @fopen($path, 'rb')) !== false) {  
                $data = '';  
                while (!feof($fp)) {  
                    $data .= fread($fp, 4096);  
                }  
                fclose($fp);  
                return $this->LoadData($data);  
            }  
            return false;  
        }  
        /**
         * Ico::LoadData()
         * Load an ICO data. If you prefer to open the file
         * and return the binary data you can use this function
         * directly. Otherwise use LoadFile() instead.
         *
         * @param   string   $data   Binary data of ICO file
         * @return  boolean          Success
         **/  
        function LoadData($data) {  
            $this->formats = array();  
            /**
             * ICO header
             **/  
            $icodata = unpack("SReserved/SType/SCount", $data);  
            $this->ico = $icodata;  
            $data = substr($data, 6);  
            
            /**
             * Extract each icon header
             **/  
            for ($i = 0; $i < $this->ico['Count']; $i ++) {  
                $icodata = unpack("CWidth/CHeight/CColorCount/CReserved/SPlanes/SBitCount/LSizeInBytes/LFileOffset", $data);  
                $icodata['FileOffset'] -= ($this->ico['Count'] * 16) + 6;  
                if ($icodata['ColorCount'] == 0) $icodata['ColorCount'] = 256;  
                $this->formats[] = $icodata;  
                $data = substr($data, 16);  
            }  
            /**
             * Extract aditional headers for each extracted icon header
             **/  
            for ($i = 0; $i < count($this->formats); $i++) {  
                $icodata = unpack("LSize/LWidth/LHeight/SPlanes/SBitCount/LCompression/LImageSize/LXpixelsPerM/LYpixelsPerM/LColorsUsed/LColorsImportant", substr($data, $this->formats[$i]['FileOffset']));  
                $this->formats[$i]['header'] = $icodata;  
                $this->formats[$i]['colors'] = array();  
                $this->formats[$i]['BitCount'] = $this->formats[$i]['header']['BitCount'];  
                
                switch ($this->formats[$i]['BitCount']) {  
                    case 32:  
                    case 24:  
                        $length = $this->formats[$i]['header']['Width'] * $this->formats[$i]['header']['Height'] * ($this->formats[$i]['BitCount'] / 8);  
                        $this->formats[$i]['data'] = substr($data, $this->formats[$i]['FileOffset'] + $this->formats[$i]['header']['Size'], $length);  
                        break;  
                    case 8:  
                    case 4:  
                        $icodata = substr($data, $this->formats[$i]['FileOffset'] + $icodata['Size'], $this->formats[$i]['ColorCount'] * 4);  
                        $offset = 0;  
                        for ($j = 0; $j < $this->formats[$i]['ColorCount']; $j++) {  
                            $this->formats[$i]['colors'][] = array(  
                                'red'     => ord($icodata[$offset]),  
                                'green'    => ord($icodata[$offset + 1]),  
                                'blue'      => ord($icodata[$offset + 2]),  
                                'reserved' => ord($icodata[$offset + 3])  
                            );  
                            $offset += 4;  
                        }  
                        $length = $this->formats[$i]['header']['Width'] * $this->formats[$i]['header']['Height'] * (1 + $this->formats[$i]['BitCount']) / $this->formats[$i]['BitCount'];  
                        $this->formats[$i]['data'] = substr($data, $this->formats[$i]['FileOffset'] + ($this->formats[$i]['ColorCount'] * 4) + $this->formats[$i]['header']['Size'], $length);  
                        break;  
                    case 1:  
                        $icodata = substr($data, $this->formats[$i]['FileOffset'] + $icodata['Size'], $this->formats[$i]['ColorCount'] * 4);  
                        $this->formats[$i]['colors'][] = array(  
                                'blue'     => ord($icodata[0]),  
                                'green'    => ord($icodata[1]),  
                                'red'      => ord($icodata[2]),  
                                'reserved' => ord($icodata[3])  
                        );  
                        $this->formats[$i]['colors'][] = array(  
                                'blue'     => ord($icodata[4]),  
                                'green'    => ord($icodata[5]),  
                                'red'      => ord($icodata[6]),  
                                'reserved' => ord($icodata[7])  
                        );  
                        $length = $this->formats[$i]['header']['Width'] * $this->formats[$i]['header']['Height'] / 8;  
                        $this->formats[$i]['data'] = substr($data, $this->formats[$i]['FileOffset'] + $this->formats[$i]['header']['Size'] + 8, $length);  
                        break;  
                }  
                $this->formats[$i]['data_length'] = strlen($this->formats[$i]['data']);  
            }  
            
            return true;  
        }  
        /**
         * Ico::TotalIcons()
         * Return the total icons extracted at the moment
         *
         * @return  integer   Total icons
         **/  
        function TotalIcons() {  
            return count($this->formats);  
        }  
        
        /**
         * Ico::GetIconInfo()
         * Return the icon header corresponding to that index
         *
         * @param   integer   $index    Icon index
         * @return  resource            Icon header
         **/  
        function GetIconInfo($index) {  
            if (isset($this->formats[$index])) {  
                return $this->formats[$index];  
            }  
            return false;  
        }  
        
        /**
         * Ico::SetBackground()
         * Changes background color of extraction. You can set
         * the 3 color components or set $red = '#xxxxxx' (HTML format)
         * and leave all other blanks.
         *
         * @param   optional   integer   $red     Red component
         * @param   optional   integer   $green   Green component
         * @param   optional   integer   $blue    Blue component
         * @return             void
         **/  
        function SetBackground($red = 255, $green = 255, $blue = 255) {  
            if (is_string($red) && preg_match('/^\#[0-9a-f]{6}$/', $red)) {  
                $green = hexdec($red[3] . $red[4]);  
                $blue = hexdec($red[5] . $red[6]);  
                $red = hexdec($red[1] . $red[2]);  
            }  
            $this->bgcolor = array($red, $green, $blue);  
        }  
        
        /**
         * Ico::SetBackgroundTransparent()
         * Set background color to be saved as transparent
         *
         * @param   optional   boolean   $is_transparent   Is Transparent or not
         * @return             boolean                     Is Transparent or not
         **/  
        function SetBackgroundTransparent($is_transparent = true) {  
            return ($this->bgcolor_transparent = $is_transparent);  
        }  
        /**
         * Ico::GetImage()
         * Return an image resource with the icon stored
         * on the $index position of the ICO file
         *
         * @param   integer    $index   Position of the icon inside ICO
         * @return  resource            Image resource
         **/  
        function &GetIcon($index) {  
            if (!isset($this->formats[$index])) {  
                return false;  
            }  
            
            /**
             * create image
             **/  
            $im = imagecreatetruecolor($this->formats[$index]['Width'], $this->formats[$index]['Height']);  
            /**
             * paint background
             **/  
            $bgcolor = $this->AllocateColor($im, $this->bgcolor[0], $this->bgcolor[1], $this->bgcolor[2]);  
            imagefilledrectangle($im, 0 , 0, $this->formats[$index]['Width'], $this->formats[$index]['Height'], $bgcolor);  
            
            /**
             * set background color transparent
             **/  
            if ($this->bgcolor_transparent) {  
                imagecolortransparent($im, $bgcolor);  
            }  
            
            /**
             * allocate pallete and get XOR image
             **/  
            if (in_array($this->formats[$index]['BitCount'], array(1, 4, 8, 24))) {  
                if ($this->formats[$index]['BitCount'] != 24) {  
                    /**
                     * color pallete
                     **/  
                    $c = array();  
                    for ($i = 0; $i < $this->formats[$index]['ColorCount']; $i++) {  
                        $c[$i] = $this->AllocateColor($im, $this->formats[$index]['colors'][$i]['blue'],  
                                                           $this->formats[$index]['colors'][$i]['green'],  
                                                           $this->formats[$index]['colors'][$i]['red'],  
                                                           round($this->formats[$index]['colors'][$i]['reserved'] / 255 * 127));  
                    }  
                }  
                /**
                 * XOR image
                 **/  
                $width = $this->formats[$index]['Width'];  
                if (($width % 32) > 0) {  
                     $width += (32 - ($this->formats[$index]['Width'] % 32));  
                }  
                $offset = $this->formats[$index]['Width'] * $this->formats[$index]['Height'] * $this->formats[$index]['BitCount'] / 8;  
                $total_bytes = ($width * $this->formats[$index]['Height']) / 8;  
                $bits = '';  
                $bytes = 0;  
                $bytes_per_line = ($this->formats[$index]['Width'] / 8);  
                $bytes_to_remove = (($width - $this->formats[$index]['Width']) / 8);  
                for ($i = 0; $i < $total_bytes; $i++) {  
                    $bits .= str_pad(decbin(ord($this->formats[$index]['data'][$offset + $i])), 8, '0', STR_PAD_LEFT);  
                    $bytes++;  
                    if ($bytes == $bytes_per_line) {  
                        $i += $bytes_to_remove;  
                        $bytes = 0;  
                    }  
                }  
            }  
            /**
             * paint each pixel depending on bit count
             **/  
            switch ($this->formats[$index]['BitCount']) {  
                case 32:  
                    /**
                     * 32 bits: 4 bytes per pixel [ B | G | R | ALPHA ]
                     **/  
                    $offset = 0;  
                    for ($i = $this->formats[$index]['Height'] - 1; $i >= 0; $i--) {  
                        for ($j = 0; $j < $this->formats[$index]['Width']; $j++) {  
                            $color = substr($this->formats[$index]['data'], $offset, 4);  
                            if (ord($color[3]) > 0) {  
                                $c = $this->AllocateColor($im, ord($color[2]),  
                                                               ord($color[1]),  
                                                               ord($color[0]),  
                                                               127 - round(ord($color[3]) / 255 * 127));  
                                imagesetpixel($im, $j, $i, $c);  
                            }  
                            $offset += 4;  
                        }  
                    }  
                    break;  
                case 24:  
                    /**
                     * 24 bits: 3 bytes per pixel [ B | G | R ]
                     **/  
                    $offset = 0;  
                    $bitoffset = 0;  
                    for ($i = $this->formats[$index]['Height'] - 1; $i >= 0; $i--) {  
                        for ($j = 0; $j < $this->formats[$index]['Width']; $j++) {  
                            if ($bits[$bitoffset] == 0) {  
                                $color = substr($this->formats[$index]['data'], $offset, 3);  
                                $c = $this->AllocateColor($im, ord($color[2]), ord($color[1]), ord($color[0]));  
                                imagesetpixel($im, $j, $i, $c);  
                            }  
                            $offset += 3;  
                            $bitoffset++;  
                        }  
                    }  
                    break;  
                case 8:  
                    /**
                     * 8 bits: 1 byte per pixel [ COLOR INDEX ]
                     **/  
                    $offset = 0;  
                    for ($i = $this->formats[$index]['Height'] - 1; $i >= 0; $i--) {  
                        for ($j = 0; $j < $this->formats[$index]['Width']; $j++) {  
                            if ($bits[$offset] == 0) {  
                                $color = ord(substr($this->formats[$index]['data'], $offset, 1));  
                                imagesetpixel($im, $j, $i, $c[$color]);  
                            }  
                            $offset++;  
                        }  
                    }  
                    break;  
                case 4:  
                    /**
                     * 4 bits: half byte/nibble per pixel [ COLOR INDEX ]
                     **/  
                    $offset = 0;  
                    $maskoffset = 0;  
                    $leftbits = true;  
                    for ($i = $this->formats[$index]['Height'] - 1; $i >= 0; $i--) {  
                        for ($j = 0; $j < $this->formats[$index]['Width']; $j++) {  
                            if ($leftbits) {  
                                $color = substr($this->formats[$index]['data'], $offset, 1);  
                                $color = array(  
                                    'High' => bindec(substr(decbin(ord($color)), 0, 4)),  
                                    'Low' => bindec(substr(decbin(ord($color)), 4))  
                                );  
                                if ($bits[$maskoffset++] == 0) {  
                                    imagesetpixel($im, $j, $i, $c[$color['High']]);  
                                }  
                                $leftbits = false;  
                            } else {  
                                if ($bits[$maskoffset++] == 0) {  
                                    imagesetpixel($im, $j, $i, $c[$color['Low']]);  
                                }  
                                $offset++;  
                                $leftbits = true;  
                            }  
                        }  
                    }  
                    break;  
                case 1:  
                    /**
                     * 1 bit: 1 bit per pixel (2 colors, usually black&white) [ COLOR INDEX ]
                     **/  
                    $colorbits = '';  
                    $total = strlen($this->formats[$index]['data']);  
                    for ($i = 0; $i < $total; $i++) {  
                        $colorbits .= str_pad(decbin(ord($this->formats[$index]['data'][$i])), 8, '0', STR_PAD_LEFT);  
                    }  
                    
                    $total = strlen($colorbits);  
                    $offset = 0;  
                    for ($i = $this->formats[$index]['Height'] - 1; $i >= 0; $i--) {  
                        for ($j = 0; $j < $this->formats[$index]['Width']; $j++) {  
                            if ($bits[$offset] == 0) {  
                                imagesetpixel($im, $j, $i, $c[$colorbits[$offset]]);  
                            }  
                            $offset++;  
                        }  
                    }  
                    break;  
            }  
            
            return $im;  
        }  
        /**
         * Ico::AllocateColor()
         * Allocate a color on $im resource. This function prevents
         * from allocating same colors on the same pallete. Instead
         * if it finds that the color is already allocated, it only
         * returns the index to that color.
         * It supports alpha channel.
         *
         * @param               resource    $im       Image resource
         * @param               integer     $red      Red component
         * @param               integer     $green    Green component
         * @param               integer     $blue     Blue component
         * @param   optional    integer     $alphpa   Alpha channel
         * @return              integer               Color index
         **/  
        function AllocateColor(&$im, $red, $green, $blue, $alpha = 0) {  
            $c = imagecolorexactalpha($im, $red, $green, $blue, $alpha);  
            if ($c >= 0) {  
                return $c;  
            }  
            return imagecolorallocatealpha($im, $red, $green, $blue, $alpha);  
        }  
    }  
?>  
php fsockopen发送邮件,在linux下面报错 php_network_getaddresses: getaddrinfo failed: Name or service not known
经过不懈百度 谷歌终于发现问题
例如 smtp.qq.com 会有好多IP  只有其中几个才好使
提供一种测试方法

<?php
header('Content-Type:text/html;charset=utf-8');
function gethost($host) {
    $str = "";
    $gethost = gethostbyname($host);
    echo "尝试连接 $host ...<br>";
    if (!$gethost) {
        $str = "解析失败 (1)<HR>";
    } elseif ($gethost == $host) {
        $str = "解析失败 (2): 可能是一个无效的主机名<HR>";
    } else {
        echo "域名解析为 $gethost ...<br>";
        openhost($host);
    }
    echo $str;
}

function openhost($host) {  //连接主机
    if (function_exists('fsockopen')) {
        $fp = fsockopen($host, 25, &$errno, &$errstr, 60);
    }
    elseif(function_exists('pfsockopen')) {
            echo "服务器不支持Fsockopen,尝试pFsockopen函数 ...<br>";
            $fp = pfsockopen($host, 25, &$errno, &$errstr, 60);
        }
        else
        exit('服务器不支持Fsockopen函数');
        if (!$fp) {
            echo "代号:$errno,<br>错误原因:$errstr<HR>";
        } else {
            echo "SMTP服务器连接ok!<br>";
            fwrite($fp, "");
            $out0 = fgets($fp, 128);
            if (strncmp($out0, "220", 3) == 0) { // 判断三位字符内容
                echo '220 SMTP服务端响应正常<HR>';
            } else {
                echo '服务器端错误<HR>';
            }
        }
    }

    $site = array("smtp.126.com");

    foreach ($site as $value) {
        echo gethost($value);
    }



当输出
尝试连接 smtp.126.com ...
域名解析为 123.125.50.112 ...
SMTP服务器连接ok!
220 SMTP服务端响应正常

把IP写入到 /etc/hosts

lnmp最新配置

lrenwang , 2012/11/30 22:05 , Linux , 评论(0) , 阅读(2473) , Via 本站原创
服务器又一次更换,    4G内存200G磁盘 5M独立带宽

环境参数
Centos 6.3 64位
Nginx 1.2.5
Mysql 5.5.27
php 5.2.17
php 5.4.9

是的2套php环境 哈哈

尼玛累死我了 搞了一天
分页: 9/49 第一页 上页 4 5 6 7 8 9 10 11 12 13 下页 最后页 [ 显示模式: 摘要 | 列表 ]