Jump to content

Loop To Extract Images, Causing 'internal Server Error' ?


dannyb785

Recommended Posts

Hey all,

 

I have to grab a ton of images from a remote server and I have a script that knows the file URL of all the images and it grabs each image path, copies it and saves it into my own directory on my server. But after saving about 20 or 30 images, the script stops and I get the "500 internal server error". Any ideas how to prevent that? Or how to extend the life of the script? I'll give my code in case it helps

 

function create_image($orig_file)
{
 $original = $orig_file;     // picture being copied
 $temp = explode("/", $original);
 $new_file = $temp[6]."/".$temp[7];

 $new = $new_file;      // thumb being created

 $src_img=imagecreatefrompng($original);


 $old_x=imageSX($src_img);
 $old_y=imageSY($src_img);


 $dst_img=ImageCreateTrueColor($old_x,$old_y);
 imagecopyresampled($dst_img,$src_img,0,0,0,0,$old_x,$old_y,$old_x,$old_y); 


 imagepng($dst_img,$new); 

 imagedestroy($dst_img);
 imagedestroy($src_img);
}


$vars = array(3146,3147,3148,3149,3150,3154,3155,3156,3157,3158,3159,3161,3162,3164,3165,3166,3168,3169,3170,3171,3172);
$vars2 = array(3141,3142,3143,3144);
foreach($vars as $id)
{
 foreach($vars2 as $id2)
 {
    create_image("*image-path-here*/{$id}_{$id2}_M.png");
    create_image("*image-path-here*/{$id}_{$id2}_LQ.png");
 }
}

Link to comment
Share on other sites

most cases of 500 internal errors using curl that I have read about come from the remote server having either a timeout on persistant connections, or a limit on transactions from a spicific client within a set time period.

 

how much access do you have to the remote server?

 

I'm not using CURL, but I guess your suggestion is still similar. The server I'm moving the images to is a client's server so I don't know what his options are set to, but is there a way to prevent a timeout? I was thinking maybe just a cron job every 2 minutes to grab a few images and just let it run all day. Is that feasible?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.