Jump to content

jebego

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jebego's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Well, the project works much faster now Thanks for the warning about google, gonna have to look that up.
  2. Thanks for the replys! Looking up curl_multi_* functions now!
  3. I'm writing some script that gets a few thousand images from google. I have all the URL's stored in an array. Here's my code that gets them all and puts them into a "mosaic": function get_image($url) { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0); $fileContents = curl_exec($ch); curl_close($ch); return imagecreatefromstring($fileContents); } $image_number = 0; for($row = 0; $row < $rows; $row ++){ for($col = 0; $col < $columns; $col ++){ $copy_image = get_image($url_array[$image_number]); if(!$copy_image){ $copy_image = get_image($url_array[$image_number - 1]); } $copy_image_width = imagesx($copy_image); $copy_image_height = imagesy($copy_image); if($copy_image_width > $copy_image_height){ $copy_image_width = $copy_image_height; }else{ $copy_image_height = $copy_image_width; } imagecopyresampled($final_image, $copy_image, $size * $col, $size * $row, 0, 0, $size, $size, $copy_image_width, $copy_image_height); $image_number ++; } } Basically what this code does is goes through my URL array, and referring to the function "get_image()" which uses cURL to get the image from google, then crops/resizes the images to match the others, and pastes it onto my "canvas", $copy_image. Getting a few thousand images takes quite a while, and most of the script's time is used during the "get_image()" function calls. Is there a way I can speed this process up?
  4. For some reason, setting output_buffering to On prevents anything from displaying on my screen, then after a minute, I get a: I had this problem before, and figured out (at least I think I figured out) that there was some kind of timeout imposed where if the page didn't receive some kind of data for 1 minute, then I would get a 500 error, so I modified my output_buffering to a 4000 cap, and modified my loader() code to add the $buffer variable, which fills up this cap. My script then runs up to the point that I can't get it past now. Could this be related to the problem? Here's my loader code: function loader($percentage){ $buffer = str_repeat(".", 4096); ?> <script language="javascript"> loading.style.width = '<?php echo $percentage; ?>%'; loading_text.innerHTML = 'Loading <?php echo $percentage . " " . $buffer; ?>%'; </script> <?php ob_flush(); flush(); if($percentage == 100){ ?> <script language="javascript"> loading_text.innerHTML = 'Loaded!'; </script> <?php } } And, what do you mean by an internal/external call? Do you mean, is my code accessing external resources? It's getting the images from another site. Sorry, I haven't been using PHP for that long
  5. Ok, here are my new php.ini settings: And I just tested it again, got an error at the same time as always. Seems like it's some other kind of limit =/
  6. K, I'll try your suggestions, and I'm getting the time from using a stopwatch.
  7. Thanks for the reply! Yes, that's what's weird about it. I get the OK 200 status, but the script stops working, so it's an error. That's why I'm confused =/
  8. Update: I created another array of URL's that pointed to different images than the previous one. This one also had only 44 rows. This one ended up working! So, it seems that my theory was correct, there's some kind of limitation set in place, but I still can't figure out what it is =/
  9. So, every time I run my code, I get this error: ... and here's the last 4 errors from the error log: Because of the length of my code, I won't post it all, but here's the chunk where the error has appeared, then stopped the script: $image_number = 0; for($row = 0; $row < $rows; $row ++){ loader(60 + 30*($row / $rows)); for($col = 0; $col < $columns; $col ++){ $copy_image = imagecreatefromjpeg($url_array[$image_number]); if(!$copy_image){ $copy_image = imagecreatefromjpeg($url_array[$image_number - 1]); } $copy_image_width = imagesx($copy_image); $copy_image_height = imagesy($copy_image); if($copy_image_width > $copy_image_height){ $copy_image_width = $copy_image_height; }else{ $copy_image_height = $copy_image_width; } imagecopyresized($final_image, $copy_image, $size * $col, $size * $row, 0, 0, $size, $size, $copy_image_width, $copy_image_height); $image_number ++; } } Basically what this does is go through an array ($url_array) filled with URLs to images on another site, then scales, crops, and places them on my previously made $final_image into a kind of mosaic using imagecopyresized(). The final image is 66 by 66 images, so that's ~4000 images. The overall process should take around 12 or so minutes, but it keeps getting stopped by this error somewhere around the 9 minute mark. I've also deduced that the error comes between the 45th and 55th row changing every time I run the script. From these observations, I don't think it's a problem with any individual image I'm getting, but some kind of limit set. Because of this, I went over my php.ini file, that I had modified earlier to accommodate a high-resource script like this, here's my php.ini: I'm using PHP Version 5.2.8 and using shared linux hosting on Godaddy. Sorry about the large amount of info and such, but I think that most if not all of it's applicable. Tell me if any more information is needed So, any idea what's going on? Thanks!
  10. Thanks to this forum, figured it out. Here's a link to my first post (sorry about that) that has the answer to my problem if anyone else comes by it: http://www.phpfreaks.com/forums/index.php/topic,300239.0.html
  11. Yes! I looked up what you said, and ended up creating a loading bar. This send data to the browser which kept it from timing out. In the end, apparently the creating of the image takes ~10 minutes. I'll be looking for a way to make that smaller later. Thanks a ton!
  12. Yea, sorry about that, I thought they were individual problems in the beginning, but now I'm not so sure.
  13. I added the lines, but I'm still just getting the same error: Also, here's the error log for the 500 error Lastly, not sure if it's going to help, but I'm also having another strange problem with creating the file. After the 500 error appears, the file isn't instantly created, it takes 10 minutes for it to appear! Is the script still running for another 10 minutes? O_o Here's the last bit of code: $image_name = microtime() . ".jpeg"; imagejpeg($final_image, "mosaics/" . $image_name); imagedestroy($final_image); header('Content-Type: image/jpeg; url="mosaics/" . $image_name'); Thanks again for your time!
  14. Thanks again for the reply! I added the imagedestroy($final_image); line to my code. It didn't fix my problem, but I should have had it there anyways, as not using it can apparently cause memory problems. Any other ideas?
×
×
  • 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.