Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8306795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:24:04+00:00 2026-06-08T18:24:04+00:00

So I keep running into the same error… I’ve searched for hours to try

  • 0

So I keep running into the same error… I’ve searched for hours to try to find a resolution, but I just can’t seem to find the missing piece. Lots of other people asking about error 7 on stack overflow, but none that were similar to my scenario.

Basically, I’m using cURL to download images being sent through an XML feed. My entire script works, everything runs, the function I’ve written below even downloads thousands of images (upwards to the 3000 range sometimes).

I guess my question is, why, after downloading 3000 images would it just not connect?

function downloadImage($location, $imagesPath, $imageName) {

    //Location fix
    $location = str_replace(" ", "%20", $location);

    $url  = $location;
    $path = $imagesPath . $imageName;
    $fp = fopen($path, 'w');    

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); //Wait indefinitately      
    curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);

    $data = curl_exec($ch); 
    if ($data === false) {
      echo "DownloadImage cURL failed 1: (" . curl_errno($ch) . ") " . curl_error($ch) . "<br/>";
      //exit;
    }           
    curl_close($ch);


    fclose($fp);        

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:24:05+00:00Added an answer on June 8, 2026 at 6:24 pm

    So in order to get this to work, I had to put a bottleneck on the function to slow it down a bit. As Andrewsi suggested, the remote site was cutting me off for downloading images too quickly. In order to bottleneck the function, I FTP’d each image to a remote server (since this was required anyway).

    Final function looks like this:

    function downloadImage($location, $imagesPath, $imageName, $ch3, $feedFTPinfo) {
    
    //Location fix
    //$location = str_replace(" ", "%20", $location);   
    
    $url  = $location;
    $path = $imagesPath . $imageName;
    
    $fp = fopen($path, 'w');    
    $ch2 = curl_init(); // Initiate cURL for downloading images
    
    //Setup the cURL options for the second handle ($ch2)
    curl_setopt($ch2, CURLOPT_URL, $url);
    curl_setopt($ch2, CURLOPT_FILE, $fp);   
    curl_setopt($ch2, CURLOPT_CONNECTTIMEOUT, 0); //Wait indefinitately     
    curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);
    
    //Execute the cURL session
    $data2 = curl_exec($ch2); 
    
    //Resize Images
    $image = new SimpleImage();
    $image->load($url); 
    $imageNameSm = str_replace(".jpg", "", $imageName);
    $imageNameSm = $imageNameSm."_sm2.jpg"; 
    $image->resizeToWidth(120);
    $image->save($imagesPath . $imageNameSm);   
    $smPath = $imagesPath . $imageNameSm;
    
    //Find out if there were any issues
    if ($data2 === false) {
      echo "DownloadImage cURL failed 1: (" . curl_errno($ch2) . ") " . curl_error($ch2) . "<br/>";
      //exit;
    } else {
        //There weren't any issues downloading the file, move it to the speficifed ftp server
    
        if (!empty($feedFTPinfo)) {
    
            $localfile = $path;
            $fp = fopen($localfile, 'r');
    
            //Setup the options for the 3rd handle
            curl_setopt($ch3, CURLOPT_URL, $feedFTPinfo.$imageName);
            curl_setopt($ch3, CURLOPT_CONNECTTIMEOUT, 0); //Wait indefinitately 
            curl_setopt($ch3, CURLOPT_UPLOAD, 1);
            curl_setopt($ch3, CURLOPT_INFILE, $fp);
            curl_setopt($ch3, CURLOPT_INFILESIZE, filesize($localfile));
    
            //Execute the 3rd cURL handle
            $data3 = curl_exec($ch3);
    
            //Find out if there were any issues with the execution
            if ($data3 === false) {
                echo "Uploading the image via FTP failed: (" . curl_errno($ch3) . ") " . curl_error($ch3) . "<br/>";
                //exit;
            }
    
            $localfile = $smPath;
            $fp = fopen($localfile, 'r');
    
            //Setup the options for the 3rd handle
            curl_setopt($ch3, CURLOPT_URL, $feedFTPinfo.$imageNameSm);
            curl_setopt($ch3, CURLOPT_CONNECTTIMEOUT, 0); //Wait indefinitately 
            curl_setopt($ch3, CURLOPT_UPLOAD, 1);
            curl_setopt($ch3, CURLOPT_INFILE, $fp);
            curl_setopt($ch3, CURLOPT_INFILESIZE, filesize($localfile));
    
            //Execute the 3rd cURL handle
            $data3 = curl_exec($ch3);
    
            //Find out if there were any issues with the execution
            if ($data3 === false) {
                echo "Uploading the small image via FTP failed: (" . curl_errno($ch3) . ") " . curl_error($ch3) . "<br/>";
                //exit;
            }           
    
    
    
    
        }
    
    
    }
    
    curl_close($ch2); //Close the cURL handle that downloads images
    fclose($fp);
    }
    

    If you don’t need to ftp somewhere to create the bottleneck, you could use php’s sleep (seconds) or usleep (microseconds) functions within your downloadImage function to create a similar bottleneck.

    • sleep documentation:
      http://php.net/manual/en/function.sleep.php
    • usleep documentation:
      http://php.net/manual/en/function.usleep.php

    Hope this theory helps someone else out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep running into the same testing Failure, and I can't figure out quite
I keep running into this error MemCacheError (Broken pipe): Broken pipe on my Rails
I've been using RhinoMocks lately but I keep running into an issue. If I
I am sure this is relatively simple, I just keep running into brick walls.
I know Rails' flash hash is nothing new, but I keep running into the
Ok guys, just a quick question hopefully someone can find my mistake quickly, but
I've been struggling along with sockets, making OK progress, but I keep running into
Keep running into When using the multi-mapping APIs ensure you set the splitOn param
I keep running into the following problem: (System.Console.ReadLine ()).Split [|'('; ')'|] |> Array.filter (fun
I keep running into this design problem, and I'm not happy with my solution

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.