php fseek可以读多大文件,PHP:fseek()用于大文件(> 2GB)

对于我的项目,我需要从BIG文件(> 3 GB)中的BIG偏移读取10KB的块.写入总是附加,因此不需要补偿.

无论您使用哪种PHP版本和操作系统,这都可以使用.

先决条件=您的服务器应支持范围检索查询. Apache& IIS已经支持这一点,99%的其他Web服务器(共享托管或其他)也支持此功能

// offset, 3GB+

$start=floatval(3355902253);

// bytes to read, 100 KB

$len=floatval(100*1024);

// set up the http byte range headers

$opts = array('http'=>array('method'=>'GET','header'=>"Range: bytes=$start-".($start+$len-1)));

$context = stream_context_create($opts);

// bytes ranges header

print_r($opts);

// change the URL below to the URL of your file. DO NOT change it to a file path.

// you MUST use a http:// URL for your file for a http request to work

// this will output the results

echo $result = file_get_contents('http://127.0.0.1/dir/mydbfile.dat', false, $context);

// status of your request

// if this is empty, means http request didnt fire.

print_r($http_response_header);

// Check your file URL and verify by going directly to your file URL from a web

// browser. If http response shows errors i.e. code > 400 check you are sending the

// correct Range headers bytes. For eg - if you give a start Range which exceeds the

// current file size, it will give 406.

// NOTE - The current file size is also returned back in the http response header

// Content-Range: bytes 355902253-355903252/355904253, the last number is the file size

...

安全性 – 您必须添加.htaccess规则,该规则拒绝对此数据库文件的所有请求,但来自本地IP 127.0.0.1的请求除外.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值