KarlvonKarton Posted May 4, 2018 Share Posted May 4, 2018 I'm trying to sync a web service with Processwire and the API. I have this line in my code: $p->Pictures->add($picture['UrlXXL']); But from time to time I get following error. It is never the same picture. Error: Uncaught ProcessWire\WireException: File could not be downloaded (http://gobert.websites.whoman2.be//Pictures/2602849/1920/7dfad7eb252f4efaba17907bc69e35a3.jpg) 2: file_get_contents(http://gobert.websites.whoman2.be//Pictures/2602849/1920/7dfad7eb252f4efaba17907bc69e35a3.jpg): failed to open stream: Redirection limit reached, aborting (tried: curl, fopen) in /Users/iovalduc/Projectweb Media/Projecten/Immo-Gobert/Web/www/wire/core/WireHttp.php:703 Any ideas? Link to comment Share on other sites More sharing options...
dragan Posted May 4, 2018 Share Posted May 4, 2018 27 minutes ago, KarlvonKarton said: Redirection limit reached well, your web service server has problems, that's why. Also, this URL looks wrong to me: http://gobert.websites.whoman2.be//Pictures/2602849/1920/7dfad7eb252f4efaba17907bc69e35a3.jpg Why the double slash after whoman2.be ? Link to comment Share on other sites More sharing options...
KarlvonKarton Posted May 4, 2018 Author Share Posted May 4, 2018 Quote well, your web service server has problems, that's why. I suspected that, but was not sure. They (Whoman2) say there are no problems... Quote Also, this URL looks wrong to me: http://gobert.websites.whoman2.be//Pictures/2602849/1920/7dfad7eb252f4efaba17907bc69e35a3.jpg Why the double slash after whoman2.be ? My opinion also, but this is what I get from the JSON: "UrlXXL":"http:\/\/gobert.websites.whoman2.be\/\/Pictures\/3394302\/1920\/5331ffa436e548f6ad34e8e0450f7992.jpg" Link to comment Share on other sites More sharing options...
kongondo Posted May 4, 2018 Share Posted May 4, 2018 The URL (the one in the PW error) works fine if you access it directly. So, maybe some other formatting issue? Link to comment Share on other sites More sharing options...
KarlvonKarton Posted May 4, 2018 Author Share Posted May 4, 2018 2 minutes ago, kongondo said: The URL (the one in the PW error) works fine if you access it directly. So, maybe some other formatting issue? "formatting issue" like what? Link to comment Share on other sites More sharing options...
kongondo Posted May 4, 2018 Share Posted May 4, 2018 6 minutes ago, KarlvonKarton said: "formatting issue" like what? Oops my bad. I misread. The URL string is not malformed since it works when accessed directly. Link to comment Share on other sites More sharing options...
KarlvonKarton Posted May 4, 2018 Author Share Posted May 4, 2018 Apart from the Processwire error: I also log errors when checking if the url of the picture is a real picture like this: if(getimagesize($picture['UrlXXL'])) Sometimes i get the error (not always the same pictures): [2] getimagesize(http://gobert.websites.whoman2.be//Pictures/2602849/1920/be61d9390d4b42bb8ec1e3e1c37055e3.jpg): failed to open stream: Operation timed out Is it safe to conclude that Dragan is right about the service having trouble? Or could there be yet another problem? Link to comment Share on other sites More sharing options...
dragan Posted May 4, 2018 Share Posted May 4, 2018 I examined the code which PW uses here for this action: https://github.com/processwire/processwire/blob/master/wire/core/WireHttp.php#L703 A few lines below you'll find the cURL function: https://github.com/processwire/processwire/blob/master/wire/core/WireHttp.php#L736 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); This means (from the PHP docs): Quote TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set). In other words: PW actually follows redirects when trying to fetch a file. But when something is wrongly configured on the target server, eventually it's timing out and aborting the operation. Link to comment Share on other sites More sharing options...
KarlvonKarton Posted May 4, 2018 Author Share Posted May 4, 2018 Is there a way to prevent PW to crash on this error? Link to comment Share on other sites More sharing options...
dragan Posted May 4, 2018 Share Posted May 4, 2018 Not sure. I found $option here https://github.com/processwire/processwire/blob/master/wire/core/WireHttp.php#L629 Don't know if you can set this in your config.php file or how. It also doesn't appear to be hookable. Link to comment Share on other sites More sharing options...
KarlvonKarton Posted May 4, 2018 Author Share Posted May 4, 2018 Maybe it is not good practice to add a picture to a Processwire page from an external URL like that? Link to comment Share on other sites More sharing options...
kongondo Posted May 4, 2018 Share Posted May 4, 2018 1 hour ago, KarlvonKarton said: Maybe it is not good practice to add a picture to a Processwire page from an external URL like that? No. Not true . The docs themselves show how to add an image from an external URL. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now