本文整理汇总了PHP中connection_status函数的典型用法代码示例。如果您正苦于以下问题:PHP connection_status函数的具体用法?PHP connection_status怎么用?PHP connection_status使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connection_status函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smartReadFile
function smartReadFile($location, $filename, $mimeType = 'application/octet-stream')
{
if (!file_exists($location)) {
header("HTTP/1.0 404 Not Found");
return;
}
$size = filesize($location);
$time = date('r', filemtime($location));
$fm = fopen($location, 'r') or die("Couldn't get handle");
# ob_start();
if (!$fm) {
header("HTTP/1.0 505 Internal server error");
return;
}
$begin = 0;
$end = $size;
if (isset($_SERVER['HTTP_RANGE'])) {
if (preg_match('/bytes=\\h*(\\d+)-(\\d*)[\\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) {
$begin = intval($matches[0]);
if (!empty($matches[1])) {
$end = intval($matches[1]);
}
}
}
if ($begin > 0 || $end < $size) {
header('HTTP/1.0 206 Partial Content');
} else {
header('HTTP/1.0 200 OK');
}
header('Content-Type: application/force-download');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Accept-Ranges: bytes');
header('Content-Length:' . ($end - $begin));
header("Content-Range: bytes {$begin}-{$end}/{$size}");
header("Content-Disposition: attachment; filename={$filename}");
header('Content-Transfer-Encoding: binary');
header("Last-Modified: {$time}");
header('Connection: close');
// check for IE only headers
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) {
header("Cache-control: private");
header('Pragma: private');
} else {
header('Pragma: public');
}
$cur = $begin;
fseek($fm, $begin, 0);
while (!feof($fm) && $cur < $end && connection_status() == 0) {
print fread($fm, min(1024 * 16, $end - $cur));
$cur += 1024 * 16;
}
# ob_end_flush();
}
示例2: eventDownloadFiles
/**
* event function to download files
* @param object $evctl
* The script is using chunk download just to make sure that the large file download works without memory leak
*/
function eventDownloadFiles(EventControler $evctl)
{
if ((int) $evctl->fileid > 0) {
$this->getId((int) $evctl->fileid);
$upload_path = $GLOBALS['FILE_UPLOAD_PATH'];
$file_name = $this->file_name;
$file_desc = $this->file_description;
$file_mime = $this->file_mime;
if ($file_mime == '' || $file_mime == 'unknown') {
$file_mime = 'application/octet-stream';
}
$file_size = $this->file_size;
$saved_file_name = $file_name . '.' . $this->file_extension;
$file_download = $upload_path . '/' . $saved_file_name;
if (is_file($file_download)) {
ob_end_clean();
header("Cache-Control:no-store,no-cache,must-revalidate");
header("Cache-Control:post-check=0,pre-check=0", false);
header("Pragma:no-cache");
header("Expires:" . gmdate("D,d M Y H:i:s", mktime(date("H") + 2, date("l"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
header("Last-Modified:" . gmdate("D,d M Y H:i:s") . " GMT");
header("Content-Type:" . $file_mime);
header("Content-Length:" . $file_size);
header("Content-Disposition:inline;filename={$file_desc}");
header("Content-Transfer-Encoding:binary\n");
if ($file = fopen($file_download, 'rb')) {
while (!feof($file) and connection_status() == 0) {
print fread($file, 1024 * 8);
flush();
}
}
}
}
}
示例3: file
public function file($filePath) {
set_time_limit(0);
if (!is_file($filePath)) {
return "File does not exist. Make sure you specified correct file name.";
}
if ($mimeType = $this->getMimeType($filePath) === false) {
return "Not allowed file type.";
}
$this->setHeaders($mimeType, basename($filePath));
$file = @fopen($filePath, "rb");
if ($file) {
while(!feof($file)) {
print(fread($file, 1024*8));
flush();
if (connection_status()!=0) {
@fclose($file);
die();
}
}
@fclose($file);
}
$this->log($filePath);
die();
}
示例4: check_conn_timeout
/**
* Connection time out
*/
function check_conn_timeout()
{
$status = connection_status();
if (($status & CONNECTION_TIMEOUT) == CONNECTION_TIMEOUT) {
echo 'Got timeout';
}
}
示例5: sendFile
/**
* Start a big file download on Laravel Framework 4.0 / 4.1
* Source (originally for Laravel 3.*) : http://stackoverflow.com/questions/15942497/why-dont-large-files-download-easily-in-laravel
* @param string $path Path to the big file
* @param string $name Name of the file (used in Content-disposition header)
* @param array $headers Some extra headers
*/
public function sendFile($path, $name = null, array $headers = array())
{
if (is_null($name)) {
$name = basename($path);
}
$file = new \Symfony\Component\HttpFoundation\File\File($path);
$mime = $file->getMimeType();
// Prepare the headers
$headers = array_merge(array('Content-Description' => 'File Transfer', 'Content-Type' => $mime, 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => \File::size($path), 'Content-Disposition' => 'attachment; filename=' . $name), $headers);
$response = new \Symfony\Component\HttpFoundation\Response('', 200, $headers);
// If there's a session we should save it now
if (\Config::get('session.driver') !== '') {
\Session::save();
}
session_write_close();
if (ob_get_length()) {
ob_end_clean();
}
$response->sendHeaders();
// Read the file
if ($file = fopen($path, 'rb')) {
while (!feof($file) and connection_status() == 0) {
print fread($file, 1024 * 8);
flush();
}
fclose($file);
}
// Finish off, like Laravel would
\Event::fire('laravel.done', array($response));
$response->send();
}
示例6: file
function file($hash)
{
$file = $this->CompanyFile->find("CompanyFile.hash = '" . $hash . "'");
if ($file['CompanyFile']['public'] == '1') {
$filePath = dirname(dirname(WWW_ROOT)) . DS . "files" . DS . "uploads" . DS . $file['CompanyFile']['company_id'] . DS . $file['CompanyFile']['file'];
// Prepare headers
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public", false);
header("Content-Description: File Transfer");
header("Content-Type: " . $file['CompanyFile']['ext']);
header("Accept-Ranges: bytes");
header("Content-Disposition: attachment; filename=\"" . $file['CompanyFile']['file'] . "\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($filePath));
// Send file for download
if ($stream = fopen($filePath, 'rb')) {
while (!feof($stream) && connection_status() == 0) {
//reset time limit for big files
set_time_limit(0);
print fread($stream, 1024 * 8);
flush();
}
fclose($stream);
}
exit;
} else {
$this->notifyCustomer('Sorry, you don\'t have permission to download this file.', $this->referer(), 'error');
}
}
示例7: getJson
function getJson($url)
{
//echo urlencode($url)."</br>";
$code = http_response_code();
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL, $url);
// Execute
$result = curl_exec($ch);
if (connection_aborted()) {
echo "erra bae";
} elseif (connection_status() == CONNECTION_TIMEOUT) {
echo "<h1>Error caught, stopped from crashing</h1>";
} else {
$this->busted = false;
// any normal completion actions
}
// Closing
curl_close($ch);
return json_decode($result, true);
}
示例8: squeeze
/**
* Compress the data
*
* Checks the accept encoding of the browser and compresses the data before
* sending it to the client.
*
* @param string $data Content to compress for output.
* @return string compressed data
*/
protected function squeeze($data)
{
$encoding = $this->acceptEncoding();
if (!$encoding) {
return $data;
}
if (!extension_loaded('zlib') || ini_get('zlib.output_compression')) {
return $data;
}
if (headers_sent()) {
return $data;
}
if (connection_status() !== 0) {
return $data;
}
// Ideal level
$level = 4;
/*
$size = strlen($data);
$crc = crc32($data);
$gzdata = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
$gzdata .= gzcompress($data, $level);
$gzdata = substr($gzdata, 0, strlen($gzdata) - 4);
$gzdata .= pack("V",$crc) . pack("V", $size);
*/
$gzdata = gzencode($data, $level);
$this->headers->set('Content-Encoding', $encoding);
$this->headers->set('X-Content-Encoded-By', 'HUBzero');
return $gzdata;
}
示例9: compress
private function compress($data, $level = 0)
{
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
$encoding = 'gzip';
}
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) {
$encoding = 'x-gzip';
}
if (!isset($encoding)) {
return $data;
}
if (!extension_loaded('zlib') || ini_get('zlib.output_compression')) {
return $data;
}
if (headers_sent()) {
return $data;
}
if (connection_status()) {
return $data;
}
/*
* header('Vary: Accept-Encoding');
header("cache-control: must-revalidate");
$offset = 60 * 60;
$expire = "expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
header($expire);
*/
$this->addHeader('Content-Encoding: ' . $encoding);
$this->addHeader('Vary: Accept-Encoding');
$output = gzencode($data, (int) $level);
return $output;
}
示例10: server
function server()
{
for ($i = 0, $timeout = 10; $i < $timeout; $i++) {
if (connection_status() != 0) {
exit;
}
$where = array();
$user_id = $user_id = get_user_id();
session_write_close();
$where['user_id'] = $user_id;
$where['time'] = array('elt', time() - 1);
$model = M("Push");
$data = $model->where($where)->find();
$where['id'] = $data['id'];
//dump($model);
if ($data) {
sleep(1);
$model->where("id=" . $data['id'])->delete();
$this->ajaxReturn($data['data'], $data['info'], $data['status']);
} else {
sleep(5);
}
}
$this->ajaxReturn(null, "no-data", 0);
}
示例11: send_file
function send_file($path)
{
ob_end_clean();
if (preg_match(':\\.\\.:', $path)) {
return FALSE;
}
if (!preg_match(':^plotcache/:', $path)) {
return FALSE;
}
if (!is_file($path) or connection_status() != 0) {
return FALSE;
}
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Type: application/octet-stream");
header("Content-Length: " . (string) filesize($path));
header("Content-Disposition: inline; filename=" . basename($path));
header("Content-Transfer-Encoding: binary\n");
if ($file = fopen($path, 'rb')) {
while (!feof($file) and connection_status() == 0) {
print fread($file, 1024 * 8);
flush();
@ob_flush();
}
fclose($file);
}
return connection_status() == 0 and !connection_aborted();
}
示例12: testShutdownHookTimeout
/**
* Ensure shutdown hook terminates if connection status is TIMEOUT.
*/
public function testShutdownHookTimeout()
{
connection_status(CONNECTION_TIMEOUT);
UnlinkUploads::shutdownHook($this->files);
// Shutdown hook should exist on first loop so all files should exist.
$this->assertFilesExist();
}
示例13: send_file
function send_file($path)
{
session_write_close();
ob_end_clean();
if (!is_file($path) || connection_status() != 0) {
return false;
}
//to prevent long file from getting cut off from //max_execution_time
set_time_limit(0);
$name = basename($path);
//filenames in IE containing dots will screw up the
//filename unless we add this
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
$name = preg_replace('/\\./', '%2e', $name, substr_count($name, '.') - 1);
//required, or it might try to send the serving //document instead of the file
$name = str_replace(array("\"", "<", ">", "?", ":"), array('%22', '%3c', '%3e', '%3f', '_'), $name);
} else {
$name = str_replace(array("\"", ":"), array("'", "_"), $name);
}
header("Cache-Control: ");
header("Pragma: ");
header("Content-Type: application/octet-stream");
header("Content-Length: " . (string) filesize($path));
header('Content-Disposition: attachment; filename="' . $name . '"');
header("Content-Transfer-Encoding: binary\n");
if ($file = fopen($path, 'rb')) {
while (!feof($file) && connection_status() == 0) {
print fread($file, 1024 * 8);
flush();
}
fclose($file);
}
return connection_status() == 0 and !connection_aborted();
}
示例14: send_file
function send_file($name)
{
$path = $name;
$path_info = pathinfo($path);
$basename = $path_info['basename'];
if (!is_file($path) or connection_status() != 0) {
return false;
}
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Type: application/octet-stream");
header("Content-Length: " . (string) filesize($path));
header("Content-Disposition: inline; filename={$basename}");
header("Content-Transfer-Encoding: binary\n");
if ($file = fopen($path, 'rb')) {
while (!feof($file) and connection_status() == 0) {
print fread($file, 1024 * 8);
flush();
}
fclose($file);
}
return connection_status() == 0 and !connection_aborted();
}
示例15: processResponse
/**
* @interface ResponseService
**/
public function processResponse($model){
set_time_limit(0);
$filename = $model['file'];
$asname = $model['asname'];
$mtype = $model['mime'];
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $mtype");
header("Content-Disposition: attachment; filename=\"$asname\"");
header("Content-Transfer-Encoding: binary");
$file = @fopen($filename,"rb");
if ($file) {
while(!feof($file)) {
print(fread($file, 1024*8));
flush();
if (connection_status()!=0) {
@fclose($file);
die();
}
}
@fclose($file);
}
$model['valid'] = true;
return json_encode($model);
}