I create a zip file using ZipArchive, where I record images. The process is quite long, but VPS allows.

$zip = new ZipArchive(); $imagesZipFile = __DIR__.'/../files/images_' . $xmlCreateDatetime . '.zip'; $imageNewName = 'autocity_'.$car['id']; $i = 0; foreach($imagesArray as $image){ if($image != '..' AND $image != '.'): // Add image to zip if($zip->open($imagesZipFile, ZipArchive::CREATE)!==TRUE): continue; endif; $zip->addFile($imageDir . '/' . $image, $imageNewName.$image); // Add string to xml $ImageElt = $domDoc->createElement('Image'); $ImageName = $domDoc->createAttribute('name'); $ImageName->appendChild($domDoc->createTextNode($imageNewName.$image)); $ImageElt->appendChild($ImageName); $ImagesNode->appendChild($ImageElt); $i++; endif; } $zip->close(); 

As a result, the file is completely created, placed in the right folder, but at the end the script gives Gateway Timeout, although with small cycles it returns the desired variable.

As a result, two questions:

  1. Is it possible to somehow facilitate the process of creating an archive (maybe memory clearing or something like that)
  2. Is it possible to avoid the 504th error and, if so, how?

    1 answer 1

    If you have fast-cgi + php-fpm on the server, then you can use the fastcgi_finish_request(); function fastcgi_finish_request(); it gives the answer to the browser, while the script continues to run on the server, periodically recording somewhere the status of the task

    • I installed php-fpm on the server ( sudo apt-get install php-fpm ), but the function does not want to work for some reason (undefined). Version php 5.4 (I can not change, immediately there is a service that, when changing a version, can collapse). - user3774771