I am migrating my project from PHP 5.X to PHP 8.0.8 but I have a problem with a script. The script allows users to export the selected clip's to a zip file, I've been testing it and it seems to work fine sometimes and sometimes it returns this error:
[Mon Aug 30 09:55:21.651635 2021] [php:warn] [pid 2772] [client 10.10.2.10:47942]PHP Warning: fopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /userdata/demo/action/download_clips.php on line 164, referer: http://demo.com/index.php
[Mon Aug 30 09:55:21.651635 2021] [php:warn] [pid 2772] [client 10.10.2.10:47942] PHP Warning: fopen(http://demo.com/ec/6d703f2dc2561d902fab564f70c4a508.mp4): Failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /userdata/demo/action/download_clips.php on line 164, referer: http://demo.com/index.php
[Mon Aug 30 09:55:21.651774 2021] [php:error] [pid 2772] [client 10.10.2.10:47942] PHP Fatal error: Uncaught TypeError: feof(): Argument #1 ($stream) must be of type resource, bool given in /userdata/demo/action/download_clips.php:167\nStack trace:\n#0 /userdata/demo/action/download_clips.php(167): feof(false)\n#1 {main}\n thrown in /userdata/demo/action/download_clips.php on line 167, referer: http://demo.com/index.php
$slides = json_decode($_POST['slides']);
$files_seek = json_decode(get_files_from_slides($slides));
if($files_seek->status !== 'success' || sizeof($files_seek->data->files) == 0){
echo json_encode($files_seek);
exit;
}
$files = $files_seek->data->files;
$files_zipped = 0;
if(sizeof($files) > 0){
$tmp_file = tempnam($zip_folder, 'zp');
chmod($tmp_file, 0775);
$tmp_zip = property_is_defined($_POST['zip']) ? $zip_folder . $_POST['zip'] : tempnam($zip_folder, 'zp');
chmod($tmp_zip, 0775);
$zip = new ZipArchive();
foreach($files as $file){
if($file->src){
set_time_limit(400);
$zip->open($tmp_zip, ZipArchive::CREATE);
$handle = fopen($tmp_file, "w");
$f = fopen($file->src, 'r');
while (!feof($f)) {
fwrite($handle, fread($f, 256));
}
fclose($handle);
fclose($f);
$filename = mb_ereg_replace("([^\w\s\d\-_\[\]\(\).])", '_', $file->name);
$filename = mb_ereg_replace("([\.]{2,})", '', $filename);
$zip->addFile($tmp_file, $filename);
$files_zipped++;
$progress = ceil($files_zipped * 100 / sizeof($files));
$p = fopen($tmp_zip.".progress", "w+");
fwrite($p, $progress);
fclose($p);
$zip->close();
}
}
if(file_exists($tmp_file)) unlink($tmp_file);
$zip_name = date("YmdHis") . "_" . $_SESSION['user']['id'] . ".zip";
rename($tmp_zip, $zip_folder . $zip_name);
I have tested the links and it works, I have done ping and nslookup to the domain and it works.
What am I doing wrong ?