I am in unfamiliar territory.
I am using an API to access data from a service. In an effort to take some of the load off the service and onto our server, we are caching the images.
Here's a snippet that either pulls from cache or writes the new one to cache.
The else portion used to bePHP Code:if(file_exists($fullpath)){
//$contents=file_get_contents($fullpath);
//echo $contents;
include($fullpath);
}
else{
$url= REDACTED;
save_image($url,$fullpath);
include($fullpath);
}
The save_image function uses cURL to access an image from the service at $url. I set it to return the raw data when I tried the echo version.PHP Code:$url= REDACTED;
echo(save_image($url,$fullpath));
At first it didn't occur to me that including the jpg would work, so I used file_get_contents. I noticed it was slow, so I wanted to speed it up. I tried incude and I got various error messages on 3 of the 49 images in my test query. the errors were like this:My guess is that I need to find a way to tell it not to parse, even though it is being included. Include seems to be much faster than file_get_contents, so I'd like to stick with it if I can.Code:Parse error: syntax error, unexpected '~' in /home/user/...###thumbs.jpg on line 7 Warning: Unexpected character in input: '' (ASCII=14) state=1 in /home/user/public_html/...###thumbs.jpg on line 9 Parse error: syntax error, unexpected T_STRING in /home/user/public_html/...###thumbs.jpg on line 9 and Warning: Unexpected character in input: '' (ASCII=22) state=1 in /home/user/...###thumbs.jpg on line 8 Parse error: syntax error, unexpected T_STRING in /home/user/...###thumbs.jpg on line 8



Reply With Quote

Bookmarks