<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>侯波林的blog &#187; php分享</title>
	<atom:link href="http://houbolin.cn/blog/category/php%e5%88%86%e4%ba%ab/feed/" rel="self" type="application/rss+xml" />
	<link>http://houbolin.cn/blog</link>
	<description>PHP Perl APACHE MYSQL LINUX</description>
	<lastBuildDate>Mon, 13 Feb 2012 15:16:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>php set_time_limit() 和 sleep()</title>
		<link>http://houbolin.cn/blog/2009/12/31/php-set_time_limit-%e5%92%8c-sleep/</link>
		<comments>http://houbolin.cn/blog/2009/12/31/php-set_time_limit-%e5%92%8c-sleep/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 05:33:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php分享]]></category>

		<guid isPermaLink="false">http://houbolin.cn/blog/?p=70</guid>
		<description><![CDATA[   我们知道,在php中可以 用函数 set_time_limit() 设定脚本执行时间。
   但如下程序会造成意想不到的结果,

set_time_limit(5);
for($i=0;$i]]></description>
			<content:encoded><![CDATA[<p>   我们知道,在php中可以 用函数 set_time_limit() 设定脚本执行时间。<br />
   但如下程序会造成意想不到的结果,<br />
<pre name="code" class="php">
set_time_limit(5);
for($i=0;$i<100;$i++)                                                           
{
      echo "i=$i\n";
      sleep(1);
}
</pre><br />
执行后,会发现程序并没有在5秒后终止,而是不断的输出&#8230;..查询手册后,发现下面这句:<br />
<pre name="code" class="bash">Note: The set_time_limit() function and the configuration directive max_execution_time  only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real. 
</pre><br />
也就是说 set_time_limit()函数 仅计算脚本自己执行的时间,调用system(),io操作,数据库查询,sleep() 函数不计算在脚本执行时间之内，这就是为什么上面的脚本不会超时的原因 <img src='http://houbolin.cn/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
当然,我们还需要注意的另一个重点就是<br />
<pre name="code" class="bash">This function has no effect when PHP is running in safe mode.</pre><br />
安全模式下 set_time_limit()是不起作用的 :0</p>
]]></content:encoded>
			<wfw:commentRss>http://houbolin.cn/blog/2009/12/31/php-set_time_limit-%e5%92%8c-sleep/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>php实现图片任意比例缩放</title>
		<link>http://houbolin.cn/blog/2009/12/04/php%e5%ae%9e%e7%8e%b0%e5%9b%be%e7%89%87%e4%bb%bb%e6%84%8f%e6%af%94%e4%be%8b%e7%bc%a9%e6%94%be/</link>
		<comments>http://houbolin.cn/blog/2009/12/04/php%e5%ae%9e%e7%8e%b0%e5%9b%be%e7%89%87%e4%bb%bb%e6%84%8f%e6%af%94%e4%be%8b%e7%bc%a9%e6%94%be/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 17:02:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php分享]]></category>
		<category><![CDATA[php php-gd]]></category>

		<guid isPermaLink="false">http://houbolin.cn/blog/?p=23</guid>
		<description><![CDATA[在php项目中,或多或少的会碰到 处理图片的问题. 为了实现对图片的批量自动处理,用php写了一个类,经过测试,可以对图片进行指定尺寸的缩放处理.
需要注意的:
1  需要安装php-gd库 .
2  需要确保 save_to 的目录具有写权限
类程序如下:


class Picture
{
    private $_image_type;
    private $_image_width;
    private $_image_height;
    private $_filename;
    private $_save_to;
    /**
     * Init params of this picture
     * [...]]]></description>
			<content:encoded><![CDATA[<p>在php项目中,或多或少的会碰到 处理图片的问题. 为了实现对图片的批量自动处理,用php写了一个类,经过测试,可以对图片进行指定尺寸的缩放处理.<br />
需要注意的:<br />
1  需要安装php-gd库 .<br />
2  需要确保 save_to 的目录具有写权限</p>
<p>类程序如下:<br />
<span id="more-23"></span><!--more--><br />
<pre name="code" class="php">
class Picture
{
    private $_image_type;
    private $_image_width;
    private $_image_height;
    private $_filename;
    private $_save_to;
    /**
     * Init params of this picture
     * param  $file filename include path like(/home/test/test.jpg)
     * param  $file_suffix file_size  
     * param  $swidth
     * param  $sheight 
     * param  $save_to save_file_to  (be sure to have operation)
     * param 
     * return bool
     */
public function __construct( $file , $file_suffix , $new_width ,$new_height , $save_to="./")
    {
        if( !file_exists($file) )
              return false;

        $this->_filename = $file;
        $this->_save_to = $save_to;       
        $this->_changeimagesize( $new_width , $new_height , $file_suffix );
    }
 private function _changeimagesize( $new_width , $new_height , $file_suffix )
    {
          
        list( $width , $height , $this->_image_type ) = getimagesize( $this->_filename );
        $image_handler = imagecreatetruecolor( $new_width , $new_height );
          
        //1=gif , 2=jpg , 3=png
        if( $this->_image_type == 2 )
        {
            $image = imagecreatefromjpeg( $this->_filename );
            $type='jpeg';
        }else if ( $this->_image_type == 1 )
        {
            $image = imagecreatefromgif( $this->_filename );
            $type='gif';
        }else if ( $this->_image_type == 3 )
        {
            $image = imagecreatefrompng( $this->_filename );
            $type='png';
        }else
        {
            return false;
        }
       
        if( !headers_sent() ) header('Content-type:image/'.$type);
          
        imagecopyresampled( $image_handler , $image , 0 , 0 ,0 , 0 ,$new_width , $new_height , $width , $height );
 if( $this->_image_type == 2 )
        {
            imagejpeg( $image_handler , $save_to.$file_suffix , 100 );  
        }else if ( $this->_image_type == 3  )
        {
            imagepng( $image_handler , $save_to.$file_suffix , 100 );  
        }else if ( $this->_image_type == 1 )
        {
            imagegif( $image_handler , $save_to.$file_suffix , 100 );  
        }
          
        if( !is_file($save_to.$file_suffix) ) return false;
    }

}                                    
</pre></p>
<p>使用方法如下:</p>
<p><pre name="code" class="php">
include("change_pic.php");
                                                                                                                                 
// $file , $file_suffix , $new_width ,$new_height , $save_to="./"
$obj = new Picture( 'girl.jpg' , 'newchange.jpg' , 160 , 120 ,"./image/");
if( !$obj ) 
{
      echo 'Change image size error';
      return false;
}
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://houbolin.cn/blog/2009/12/04/php%e5%ae%9e%e7%8e%b0%e5%9b%be%e7%89%87%e4%bb%bb%e6%84%8f%e6%af%94%e4%be%8b%e7%bc%a9%e6%94%be/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

