I have a long function that uses imagecreatefromjpeg()
.
function myFunction() {
...
...
$im = imagecreatetruecolor(600, 400);
$myImage = imagecreatefromjpeg("http://example.com/file.jpeg");
imagecopy($im, $myImage , 5, 5, 0, 0, 48, 48);
...
...
...
...
}
I load jpeg file from remote URL. So due to server load sometimes I get:
Warning: Warning (2): imagecreatefromjpeg(http://example.com/file.jpeg):
failed to open stream: Connection timed out in
[/var/www/vhosts/example2.com/httpdocs/myfile.php, line 1851]
All execution time is spent for this file, so request becomes unsuccessfull for the rest of my function
Although I need to download up to date jpeg file, running remaining code is acceptable for me.
I look for such a solution:
- Try this: create image from jpeg file
- If not successfull after 5 seconds, skip
- Run remaining code.
Edit:
- I get this error occasionally. Most of the requests successfull. So allow_url_fopen isn't a problem.
- This jpeg file changes frequently, like once an hour.