dannyb785 Posted October 31, 2012 Share Posted October 31, 2012 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"); } } Quote Link to comment https://forums.phpfreaks.com/topic/270106-loop-to-extract-images-causing-internal-server-error/ Share on other sites More sharing options...
Muddy_Funster Posted October 31, 2012 Share Posted October 31, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/270106-loop-to-extract-images-causing-internal-server-error/#findComment-1388967 Share on other sites More sharing options...
dannyb785 Posted October 31, 2012 Author Share Posted October 31, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/270106-loop-to-extract-images-causing-internal-server-error/#findComment-1389087 Share on other sites More sharing options...
Muddy_Funster Posted October 31, 2012 Share Posted October 31, 2012 feesable, but may be unnescassery, you could try just batching within the script, changing the php timeout setting and using a sleep between each batch Quote Link to comment https://forums.phpfreaks.com/topic/270106-loop-to-extract-images-causing-internal-server-error/#findComment-1389097 Share on other sites More sharing options...
PFMaBiSmAd Posted November 1, 2012 Share Posted November 1, 2012 Why not just use an FTP client to grab all the files from one server and upload them to the other server? Quote Link to comment https://forums.phpfreaks.com/topic/270106-loop-to-extract-images-causing-internal-server-error/#findComment-1389165 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.