Page 1 of 1

Show external images - best/fastest way?

Posted: Wed Sep 12, 2012 4:55 pm
by Guldstrand
I'm working on developing a Webcam portal for Scandinavia, and would need some help.

There are about 300 webcams portal, (we have been given permission to display them).
Given that several webcam operators/owners do not want everyone to be able to see the direct link to their cameras, I had to "hide" the links using a php-file.

I collect and read all external images via a php file, and this makes the images load very slowly.
Is there an ultimate way to speed this up?

Below are parts of the code that I use to view the images.

Code: Select all

$bild = "link-to-external-image";

header ("Content-type: image/jpeg");

$string = "mydomain.com";
$font = 4;
$width = imagefontwidth($font) * strlen($string) ;
$height = imagefontheight($font) ;
$im = imagecreatefromjpeg($bild);
$x = imagesx($im) - $width -5;
$y = imagesy($im) - $height -5;
$backgroundColor = imagecolorallocate ($im, 255, 255, 255);
$textColor = imagecolorallocate ($im, 255, 255, 255);
imagestring ($im, $font, $x, $y,  $string, $textColor);
imagejpeg($im);

Re: Show external images - best/fastest way?

Posted: Thu Sep 13, 2012 1:39 pm
by tr0gd0rr
If you are going to create a copy of the image you can use copy() as long as remote url fopen is enabled. If you do need to use gd for some reason, cache the resulting image instead of creating it every time.

But maybe the simplest solution is to just send a 302 or 303 header:

Code: Select all

header('HTTP/1.1 303 See other'); // If you omit this line, a 302 "Moved temporarily" will automatically be sent instead
header("Location: $bild");
die();

Re: Show external images - best/fastest way?

Posted: Thu Sep 13, 2012 1:49 pm
by Guldstrand
Thanks for your reply.
I've allready "replaced" the GD-function, with readfile(), and that made the images load a LITTLE faster.

Since i'm working with webcam images, that changes every 10 seconds (as min.), cache won't do it.
Any other tips on how i can speed it up even more? The images is still loading pretty slow. :(

Re: Show external images - best/fastest way?

Posted: Mon Sep 17, 2012 1:09 pm
by tr0gd0rr
At that point maybe start looking at the server load? Maybe you need a beefier server.

Re: Show external images - best/fastest way?

Posted: Mon Sep 17, 2012 4:11 pm
by flying_circus
Perhaps I dont completely understand what you are trying to do, but can you use curl and save the image to the local drive, then host the images from your server?

What kind of internet connection do the cameras have? If the link is saturated with requests, it will move slowly.

Re: Show external images - best/fastest way?

Posted: Mon Sep 17, 2012 5:56 pm
by Guldstrand
flying_circus wrote:Perhaps I dont completely understand what you are trying to do, but can you use curl and save the image to the local drive, then host the images from your server?

What kind of internet connection do the cameras have? If the link is saturated with requests, it will move slowly.
I have no idea what each camera has for speed/bandwidth.
And i can't downloaded all the images to my server, every 10 seconds. This means that the server will have to work even more. :(

Re: Show external images - best/fastest way?

Posted: Mon Sep 17, 2012 7:15 pm
by Weiry
Guldstrand wrote:I have no idea what each camera has for speed/bandwidth.
And i can't downloaded all the images to my server, every 10 seconds. This means that the server will have to work even more. :(
That is generally how things works when you have a service which is constantly updating. At some point you have to make a choice about how often you want them to update. Besides... servers are there to work, if they aren't doing something, they are wasting time and resources.
flying_circus wrote:Perhaps I dont completely understand what you are trying to do, but can you use curl and save the image to the local drive, then host the images from your server?
flying_circus has a very good point, This would be the easiest solution would be to simply download the images if possible.

As a suggestion, i wouldn't be storing more than a single image from a given camera at any time. This means that you don't have to worry about storage and if your always using the same file name for storing the images, your pages could automatically refresh to show the updated image.

Re: Show external images - best/fastest way?

Posted: Tue Sep 18, 2012 7:25 am
by Guldstrand
Hard drive space is no problem.
Since I also want to be able to show a live streams on the page (the main purpose of a Webcam portal), there is little sense to save the images on my server.

But I really appreciate all the tips and ideas.