diff --git a/upload/install/include/install_function.php b/upload/install/include/install_function.php index 9b093886b20c155319f2a755edfd860ac12bd134..7a3ca5edea8fc465ec87b60a1667be20311338ac 100644 --- a/upload/install/include/install_function.php +++ b/upload/install/include/install_function.php @@ -876,10 +876,10 @@ function fsocketopen($hostname, $port = 80, &$errno, &$errstr, $timeout = 15) { function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $return = ''; $matches = parse_url($url); - $scheme = $matches['scheme']; + $scheme = strtolower($matches['scheme']); $host = $matches['host']; - $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/'; - $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); + $path = !empty($matches['path']) ? $matches['path'].(!empty($matches['query']) ? '?'.$matches['query'] : '') : '/'; + $port = !empty($matches['port']) ? $matches['port'] : ($scheme == 'https' ? 443 : 80); if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { $ch = curl_init(); @@ -925,6 +925,9 @@ function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ $out = "POST $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; + if($allowcurl) { + $encodetype = 'URLENCODE'; + } $boundary = $encodetype == 'URLENCODE' ? '' : '; boundary='.trim(substr(trim($post), 2, strpos(trim($post), "\n") - 2)); $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n"; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; @@ -946,22 +949,35 @@ function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ } $fpflag = 0; - if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { - $context = array( - 'http' => array( - 'method' => $post ? 'POST' : 'GET', - 'header' => $header, - 'content' => $post, - 'timeout' => $timeout, - ), - 'ssl' => array( - 'verify_peer' => false, - 'verify_peer_name' => false, - ), + $context = array(); + if($scheme == 'https') { + $context['ssl'] = array( + 'verify_peer' => false, + 'verify_peer_name' => false, + 'peer_name' => $host ); + if(version_compare(PHP_VERSION, '5.6.0', '<')) { + $context['ssl']['SNI_enabled'] = true; + $context['ssl']['SNI_server_name'] = $host; + } + } + if(ini_get('allow_url_fopen')) { + $context['http'] = array( + 'method' => $post ? 'POST' : 'GET', + 'header' => $header, + 'timeout' => $timeout + ); + if($post) { + $context['http']['content'] = $post; + } $context = stream_context_create($context); - $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context); + $fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context); $fpflag = 1; + } elseif(function_exists('stream_socket_client')) { + $context = stream_context_create($context); + $fp = @stream_socket_client(($scheme == 'https' ? 'ssl://' : '').($ip ? $ip : $host).':'.$port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context); + } else { + $fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout); } if(!$fp) { @@ -969,7 +985,9 @@ function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ } else { stream_set_blocking($fp, $block); stream_set_timeout($fp, $timeout); - @fwrite($fp, $out); + if(!$fpflag) { + @fwrite($fp, $out); + } $status = stream_get_meta_data($fp); if(!$status['timed_out']) { while (!feof($fp) && !$fpflag) { diff --git a/upload/uc_client/client.php b/upload/uc_client/client.php index 9e050bd95c9bea100a0e798b0b4ed3cc70db8959..02a9d4431ef10040b3cfaf19f196975b052ba11a 100644 --- a/upload/uc_client/client.php +++ b/upload/uc_client/client.php @@ -225,10 +225,10 @@ function uc_fopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $return = ''; $matches = parse_url($url); - $scheme = $matches['scheme']; + $scheme = strtolower($matches['scheme']); $host = $matches['host']; - $path = $matches['path'] ? $matches['path'].(isset($matches['query']) && $matches['query'] ? '?'.$matches['query'] : '') : '/'; - $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); + $path = !empty($matches['path']) ? $matches['path'].(!empty($matches['query']) ? '?'.$matches['query'] : '') : '/'; + $port = !empty($matches['port']) ? $matches['port'] : ($scheme == 'https' ? 443 : 80); if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { $ch = curl_init(); @@ -274,9 +274,13 @@ function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $out = "POST $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; - $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; + if($allowcurl) { + $encodetype = 'URLENCODE'; + } + $boundary = $encodetype == 'URLENCODE' ? '' : '; boundary='.trim(substr(trim($post), 2, strpos(trim($post), "\n") - 2)); + $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n"; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; - $header .= "Host: $host\r\n"; + $header .= "Host: $host:$port\r\n"; $header .= 'Content-Length: '.strlen($post)."\r\n"; $header .= "Connection: Close\r\n"; $header .= "Cache-Control: no-cache\r\n"; @@ -287,29 +291,42 @@ function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; - $header .= "Host: $host\r\n"; + $header .= "Host: $host:$port\r\n"; $header .= "Connection: Close\r\n"; $header .= "Cookie: $cookie\r\n\r\n"; $out .= $header; } $fpflag = 0; - if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { - $context = array( - 'http' => array( - 'method' => $post ? 'POST' : 'GET', - 'header' => $header, - 'content' => $post, - 'timeout' => $timeout, - ), - 'ssl' => array( - 'verify_peer' => false, - 'verify_peer_name' => false, - ), + $context = array(); + if($scheme == 'https') { + $context['ssl'] = array( + 'verify_peer' => false, + 'verify_peer_name' => false, + 'peer_name' => $host ); + if(version_compare(PHP_VERSION, '5.6.0', '<')) { + $context['ssl']['SNI_enabled'] = true; + $context['ssl']['SNI_server_name'] = $host; + } + } + if(ini_get('allow_url_fopen')) { + $context['http'] = array( + 'method' => $post ? 'POST' : 'GET', + 'header' => $header, + 'timeout' => $timeout + ); + if($post) { + $context['http']['content'] = $post; + } $context = stream_context_create($context); - $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context); + $fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context); $fpflag = 1; + } elseif(function_exists('stream_socket_client')) { + $context = stream_context_create($context); + $fp = @stream_socket_client(($scheme == 'https' ? 'ssl://' : '').($ip ? $ip : $host).':'.$port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context); + } else { + $fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout); } if(!$fp) { @@ -317,7 +334,9 @@ function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, } else { stream_set_blocking($fp, $block); stream_set_timeout($fp, $timeout); - @fwrite($fp, $out); + if(!$fpflag) { + @fwrite($fp, $out); + } $status = stream_get_meta_data($fp); if(!$status['timed_out']) { while (!feof($fp) && !$fpflag) { diff --git a/upload/uc_client/model/misc.php b/upload/uc_client/model/misc.php index 5d60abda77d6c35c47cc2a44a1d4de686c2734f8..c50c1999118df9ab1f4361fc89ef7f4e89b5c048 100644 --- a/upload/uc_client/model/misc.php +++ b/upload/uc_client/model/misc.php @@ -61,13 +61,13 @@ class miscmodel { return $this->dfopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype, $allowcurl); } - function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { + function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $return = ''; $matches = parse_url($url); - $scheme = $matches['scheme']; + $scheme = strtolower($matches['scheme']); $host = $matches['host']; - $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/'; - $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); + $path = !empty($matches['path']) ? $matches['path'].(!empty($matches['query']) ? '?'.$matches['query'] : '') : '/'; + $port = !empty($matches['port']) ? $matches['port'] : ($scheme == 'https' ? 443 : 80); if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { $ch = curl_init(); @@ -113,7 +113,10 @@ class miscmodel { $out = "POST $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; - $boundary = $encodetype == 'URLENCODE' ? '' : ';'.substr($post, 0, trim(strpos($post, "\n"))); + if($allowcurl) { + $encodetype = 'URLENCODE'; + } + $boundary = $encodetype == 'URLENCODE' ? '' : '; boundary='.trim(substr(trim($post), 2, strpos(trim($post), "\n") - 2)); $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n"; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; $header .= "Host: $host:$port\r\n"; @@ -134,22 +137,35 @@ class miscmodel { } $fpflag = 0; - if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { - $context = array( - 'http' => array( - 'method' => $post ? 'POST' : 'GET', - 'header' => $header, - 'content' => $post, - 'timeout' => $timeout, - ), - 'ssl' => array( - 'verify_peer' => false, - 'verify_peer_name' => false, - ), + $context = array(); + if($scheme == 'https') { + $context['ssl'] = array( + 'verify_peer' => false, + 'verify_peer_name' => false, + 'peer_name' => $host ); + if(version_compare(PHP_VERSION, '5.6.0', '<')) { + $context['ssl']['SNI_enabled'] = true; + $context['ssl']['SNI_server_name'] = $host; + } + } + if(ini_get('allow_url_fopen')) { + $context['http'] = array( + 'method' => $post ? 'POST' : 'GET', + 'header' => $header, + 'timeout' => $timeout + ); + if($post) { + $context['http']['content'] = $post; + } $context = stream_context_create($context); - $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context); + $fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context); $fpflag = 1; + } elseif(function_exists('stream_socket_client')) { + $context = stream_context_create($context); + $fp = @stream_socket_client(($scheme == 'https' ? 'ssl://' : '').($ip ? $ip : $host).':'.$port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context); + } else { + $fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout); } if(!$fp) { @@ -157,7 +173,9 @@ class miscmodel { } else { stream_set_blocking($fp, $block); stream_set_timeout($fp, $timeout); - @fwrite($fp, $out); + if(!$fpflag) { + @fwrite($fp, $out); + } $status = stream_get_meta_data($fp); if(!$status['timed_out']) { while (!feof($fp) && !$fpflag) { diff --git a/upload/uc_server/install/func.inc.php b/upload/uc_server/install/func.inc.php index 3d09cf1a5f600fbad61cffc258d42e6141843015..4456056ea343107cdd7b9866e6633a40a5aa5703 100644 --- a/upload/uc_server/install/func.inc.php +++ b/upload/uc_server/install/func.inc.php @@ -746,10 +746,10 @@ function fsocketopen($hostname, $port = 80, &$errno, &$errstr, $timeout = 15) { function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $return = ''; $matches = parse_url($url); - $scheme = $matches['scheme']; + $scheme = strtolower($matches['scheme']); $host = $matches['host']; - $path = $matches['path'] ? $matches['path'].(isset($matches['query']) && $matches['query'] ? '?'.$matches['query'] : '') : '/'; - $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); + $path = !empty($matches['path']) ? $matches['path'].(!empty($matches['query']) ? '?'.$matches['query'] : '') : '/'; + $port = !empty($matches['port']) ? $matches['port'] : ($scheme == 'https' ? 443 : 80); if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { $ch = curl_init(); @@ -795,9 +795,13 @@ function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ $out = "POST $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; - $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; + if($allowcurl) { + $encodetype = 'URLENCODE'; + } + $boundary = $encodetype == 'URLENCODE' ? '' : '; boundary='.trim(substr(trim($post), 2, strpos(trim($post), "\n") - 2)); + $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n"; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; - $header .= "Host: $host\r\n"; + $header .= "Host: $host:$port\r\n"; $header .= 'Content-Length: '.strlen($post)."\r\n"; $header .= "Connection: Close\r\n"; $header .= "Cache-Control: no-cache\r\n"; @@ -808,29 +812,42 @@ function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; - $header .= "Host: $host\r\n"; + $header .= "Host: $host:$port\r\n"; $header .= "Connection: Close\r\n"; $header .= "Cookie: $cookie\r\n\r\n"; $out .= $header; } $fpflag = 0; - if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { - $context = array( - 'http' => array( - 'method' => $post ? 'POST' : 'GET', - 'header' => $header, - 'content' => $post, - 'timeout' => $timeout, - ), - 'ssl' => array( - 'verify_peer' => false, - 'verify_peer_name' => false, - ), + $context = array(); + if($scheme == 'https') { + $context['ssl'] = array( + 'verify_peer' => false, + 'verify_peer_name' => false, + 'peer_name' => $host ); + if(version_compare(PHP_VERSION, '5.6.0', '<')) { + $context['ssl']['SNI_enabled'] = true; + $context['ssl']['SNI_server_name'] = $host; + } + } + if(ini_get('allow_url_fopen')) { + $context['http'] = array( + 'method' => $post ? 'POST' : 'GET', + 'header' => $header, + 'timeout' => $timeout + ); + if($post) { + $context['http']['content'] = $post; + } $context = stream_context_create($context); - $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context); + $fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context); $fpflag = 1; + } elseif(function_exists('stream_socket_client')) { + $context = stream_context_create($context); + $fp = @stream_socket_client(($scheme == 'https' ? 'ssl://' : '').($ip ? $ip : $host).':'.$port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context); + } else { + $fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout); } if(!$fp) { @@ -838,7 +855,9 @@ function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ } else { stream_set_blocking($fp, $block); stream_set_timeout($fp, $timeout); - @fwrite($fp, $out); + if(!$fpflag) { + @fwrite($fp, $out); + } $status = stream_get_meta_data($fp); if(!$status['timed_out']) { while (!feof($fp) && !$fpflag) { diff --git a/upload/uc_server/model/misc.php b/upload/uc_server/model/misc.php index 9ab23336b653298dff8278c44486758ab761694f..ba6409e5d56ab61a25beb0b9232abdaa049b2e2f 100644 --- a/upload/uc_server/model/misc.php +++ b/upload/uc_server/model/misc.php @@ -59,13 +59,13 @@ class miscmodel { return $this->dfopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype, $allowcurl); } - function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { + function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $return = ''; $matches = parse_url($url); - $scheme = $matches['scheme']; + $scheme = strtolower($matches['scheme']); $host = $matches['host']; - $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/'; - $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); + $path = !empty($matches['path']) ? $matches['path'].(!empty($matches['query']) ? '?'.$matches['query'] : '') : '/'; + $port = !empty($matches['port']) ? $matches['port'] : ($scheme == 'https' ? 443 : 80); if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { $ch = curl_init(); @@ -111,7 +111,10 @@ class miscmodel { $out = "POST $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; - $boundary = $encodetype == 'URLENCODE' ? '' : ';'.substr($post, 0, trim(strpos($post, "\n"))); + if($allowcurl) { + $encodetype = 'URLENCODE'; + } + $boundary = $encodetype == 'URLENCODE' ? '' : '; boundary='.trim(substr(trim($post), 2, strpos(trim($post), "\n") - 2)); $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n"; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; $header .= "Host: $host:$port\r\n"; @@ -132,22 +135,35 @@ class miscmodel { } $fpflag = 0; - if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { - $context = array( - 'http' => array( - 'method' => $post ? 'POST' : 'GET', - 'header' => $header, - 'content' => $post, - 'timeout' => $timeout, - ), - 'ssl' => array( - 'verify_peer' => false, - 'verify_peer_name' => false, - ), + $context = array(); + if($scheme == 'https') { + $context['ssl'] = array( + 'verify_peer' => false, + 'verify_peer_name' => false, + 'peer_name' => $host ); + if(version_compare(PHP_VERSION, '5.6.0', '<')) { + $context['ssl']['SNI_enabled'] = true; + $context['ssl']['SNI_server_name'] = $host; + } + } + if(ini_get('allow_url_fopen')) { + $context['http'] = array( + 'method' => $post ? 'POST' : 'GET', + 'header' => $header, + 'timeout' => $timeout + ); + if($post) { + $context['http']['content'] = $post; + } $context = stream_context_create($context); - $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context); + $fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context); $fpflag = 1; + } elseif(function_exists('stream_socket_client')) { + $context = stream_context_create($context); + $fp = @stream_socket_client(($scheme == 'https' ? 'ssl://' : '').($ip ? $ip : $host).':'.$port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context); + } else { + $fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout); } if(!$fp) { @@ -155,7 +171,9 @@ class miscmodel { } else { stream_set_blocking($fp, $block); stream_set_timeout($fp, $timeout); - @fwrite($fp, $out); + if(!$fpflag) { + @fwrite($fp, $out); + } $status = stream_get_meta_data($fp); if(!$status['timed_out']) { while (!feof($fp) && !$fpflag) {