background image

stream_context_create(

$opts

)))===FALSE) 

$cnt

++;

以上方法对付超时已经

OK 了。那么 Post 呢?细心点有人发现了'method'=>”GET”, 对!是不

是能设置成

post 呢?百度找了下相关资料,还真可以!而且有人写出了山寨版的 post 传值

函数,如下:
复制代码

 代码如下:

 

function

 Post(

$url

$post

 = null){   

    

$context

 = 

array

 ();   

    

if

 (

is_array

 ( 

$post

 )) {   

        

ksort ( 

$post

 );   

        

$context

 ['http'] = 

array

 (   

            

'timeout' => 60,    

            

'method' => 'POST',    

            

'content' => http_build_query( 

$post

, '', '&' )   

         

);   

 

    

}   

    

return

 

file_get_contents

 ( 

$url

, false, stream_context_create ( 

$context

 ) );   

}   
 

 

$data

 = 

array

 (   

    

'name' => 'test',   

    

'email' => 'admin@admin.com',   

    

'submit' => 'submit',   

);   

echo

 Post ( 'http://php.yl1001.com', 

$data

 );