0

hi i am using below code to check the size of remote image .it works but it takes lot of time to check the size of image is there any bette rway to do

<?php
  $url='http://testfile.com/test/sddkssk.jpg';
  $head = array_change_key_case(get_headers($url, TRUE));
  $filesize = $head['content-length'];
  if ($filesize >= 131000) {     
    echo 'good image';
  }

but it takes 2-3 minute for each time to load is there any better way which can do same work very fast

ComFreek
  • 29,044
  • 18
  • 104
  • 156
Priya
  • 165
  • 1
  • 12
  • 3
    How large is the image? Is it possible that the remote server doesn't understand the request for only the headers? Is it faster when you make the request in your browser? – Pekka Dec 20 '13 at 15:59
  • @Pekka웃 this script is very slow from browsers also but all images loads fast when we directly paste the imaage url in browser – Priya Dec 20 '13 at 16:02
  • Profile your code and see *exactly* where the bottleneck is. Are you sure it's with `get_headers`? – ʰᵈˑ Dec 20 '13 at 16:03
  • If it's very slow in the browser as well, then it's likely an issue with the remote server? There may be nothing you can do. – Pekka Dec 20 '13 at 16:03
  • 1
    Related [Remote file size without downloading file](http://stackoverflow.com/q/2602612/1607098) – Touki Dec 20 '13 at 16:04
  • Are the server where you are running the script and the browser you are using on the same internet connection? Also, images may appear to load fast if they are cached, use a "private window" or something similar to see how fast they really load. – jeroen Dec 20 '13 at 16:05
  • @Pekka웃 pleas ehelp it is taking years to load – Priya Dec 20 '13 at 16:39
  • If it's a problem with the remote server, there may not be anything you can do. Do you have to do this often? Are you using some form of caching? – Pekka Dec 20 '13 at 16:41
  • @Pekka웃 is there any improvement can be done in my codes? – Priya Dec 20 '13 at 16:45
  • Regarding the speed? Not really. As said, the problem seems to be not caused by your code, but by the remote server. – Pekka Dec 20 '13 at 16:46

1 Answers1

0
$size = getimagesize("http://www.example.com/gifs/logo.gif");

// if the file name has space in it, encode it properly
$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
Sorbo
  • 339
  • 1
  • 5
  • yes it is mixed type of files space is thr in few and in few it is not there. can u plz explain how to do this in my code – Priya Dec 20 '13 at 16:05
  • This will load the entire file first. It's not going to help the OP who is experiencing problems even when loading *just the headers* – Pekka Dec 20 '13 at 16:11