Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TechKat's avatar

Background Job

I'm a noob when it comes to Laravel, and still learning 4.2...

Anyway, I have an admin panel for an image hosting website I own and run. A couple of features I have for it is exporting uploaded images to a ZIP folder in a backups folder.

However, because there's thousands of images to zip, the server times out after so long.

What would be the easiest way for me to have Laravel run this in the background and store it into the backups folder automatically?

0 likes
1 reply
RobinMalfait's avatar

You can try to use beanstalkd or iron.io; if you setup the credentials for it you can do this:

Queue::push(function() 
{
    $pathToStore = public_path() . '/backups';
    $pathToImages = public_path() . '/imgs'; // Your images folder

    $zipFIle = "Backup-" . (new Carbon\Carbon())->format('Y-m-d') . ".zip"; // Backup-2015-05-9.zip

    $zip = new ZipArchive;
    if ($zip->open($pathToStore. '/' . $zipFile, ZipArchive::CREATE) === true) 
    {
        foreach (glob($pathToImages . '/*') as $fileName) 
        {
                    $file = basename($fileName);                
                    $zip->addFile($fileName, $file);
        }                       
        $zip->close();
    }
});

If you still get a timeout, you can try this:

set_time_limit(0); // infinity

But that is not recommended

1 like

Please or to participate in this conversation.