mardi 30 juin 2015

php file download sometimes not working (gzopen, gzwrite, gzclose)

$myfile = gzopen($constpath . '.gz', 'w');
if (!$myfile){
    throw new \UnexpectedValueException('could not open datafeed.gz file');
$mystream = gzopen($constURL, 'r');
if (!$mystream){
    throw new \UnexpectedValueException('could not open gzip remote file');
echo '1<br>';
while (!gzeof($mystream)){
$data = gzread($mystream, 8096);
gzwrite($myfile, $data);
echo '4<br>';
echo '5<br>';
echo 'down done';

//begin ungzip

$fp = fopen($constpath . '.csv', 'w');
$gz = gzopen($constpath . '.gz', 'r');

if (!$gz){
    throw new \UnexpectedValueException(
         'could not open gzip file'
if (!fp){
    throw new \UnexpectedValueException(
        'could not open destination file'

while (!gzeof($gz)) {
    fwrite($fp, gzread($gz, 8096));
echo 'ungzip done';

Hi, guys so above is my code, it intermittently allows me to download the gz file then unzip it, however it does not seem to be doing this in any sort of pattern or anything else, is there anything i need to know about how to use these functions like maybe is there a limit on the URL length (it's currently about 2.5K characters) but unfortunately not something i can change. what would people recommend on how to debug if there're bugs? or what i can do?


Aucun commentaire:

Enregistrer un commentaire