We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

PHP errors with Rest module (Curl related)

Development and Programming

e-man's avatar
e-man
1,816 posts
15 years ago
e-man's avatar e-man

I’ve installed Phil Sturgeon’s REST module http://devot-ee.com/add-ons/rest/ which is now able to parse feeds. On my local (MAMP) install it works just fine but on my live site I keep hitting php errors. (what I’m trying to do is parse my Delicious feed - again on my local install this works fine)

On the live server I keep getting the following php errors when using it in an EE template: A PHP Error was encountered

Severity: Warning

Message: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set

Filename: libraries/Curl.php

Line Number: 248

and

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /www/pmh5232/public_html/system/expressionengine/third_party/rest/libraries/Curl.php:300)

Filename: core/Common.php

Line Number: 428

The output of the template can be checked here: http://www.stookstudio.com/index.php/rest

Does anyone have any suggestions? I’ve already contacted Phil, he’s stumped too. Safe mode is off and open_basedir has a local value but no master value when I check the php info.

(admins: if this in the wrong forum then by all means move this).

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

open_basedir having a local value will trigger this error for you when you try to enable the CURLOPT_FOLLOWLOCATION option (this is what tells Curl to automatically follow any redirects it might receive). People using my Simple S3 Uploader add-on were also running into this issue. EngineHosting uses open_basedir so it is a fairly prevalent issue for many people using EE.

If you’re fairly certain that your API isn’t going to redirect you, you can safely disable this option. Here’s the code I used to conditionally enable this option in my add-on only for people not using open_basedir on their server:

if(!ini_get('open_basedir')) {
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
}
       
Phil Sturgeon's avatar
Phil Sturgeon
2,889 posts
15 years ago
Phil Sturgeon's avatar Phil Sturgeon

I just had to add something very similar for safe mode users, i’ll throw this in for the next version.

Line 246 of pi.rest.php

if ( ! ini_get('safe_mode') AND ! ini_get('open_basedir'))
       
e-man's avatar
e-man
1,816 posts
15 years ago
e-man's avatar e-man

Thanks @ender and @phil

Changing that line doesn’t solve the issue, but the output of the template has changed. http://www.stookstudio.com/index.php/rest

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

We use that code when we use cURL. What errors are you receiving?

       
e-man's avatar
e-man
1,816 posts
15 years ago
e-man's avatar e-man

@Greg You can check the output here: The output of the template can be checked here: http://www.stookstudio.com/index.php/rest

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

i only get a <ul> </ul> when viewing source. can you copy the src of what you see & upload here in a zip file?

       
e-man's avatar
e-man
1,816 posts
15 years ago
e-man's avatar e-man

Sure, please have a look at at the attached zip. Source_1 is the output with the original line 246 in pi.rest.php

if ( ! ini_get('safe_mode'))

Source_2 is with the amended line 246

if ( ! ini_get('safe_mode') && ! ini_get('open_basedir'))

My template code is just a basic:

<ul>
{exp:rest name="delicious"}
<li>{description}</li>
{/exp:rest}
</ul>

With the amended line 246 it parses correctly but I’m still getting the basedir error: http://www.stookstudio.com/index.php/rest

       
e-man's avatar
e-man
1,816 posts
15 years ago
e-man's avatar e-man

Ok, setting Debug Preference to 0: No PHP/SQL error messages generated removed that last error message, forgot I had this setting still on.

OK sorted! Thank you gents for all the assistance, much appreciated.

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

e-man,

honestly, I dont’ consider that a good solution, as there are still errors, even if you are suppressing them. Without access to the code, I can’t say with certainty what the issue is, however the cURL option can’t be used over at EngineHosting, as openbase_dir for each user is set to their home directory. eg: /www/eh126xx I’d work with Phil to get the errors knocked out, and make sure your debug preference is set so you are able to see errors when you’re logged in. 😊

-greg

       
e-man's avatar
e-man
1,816 posts
15 years ago
e-man's avatar e-man

Greg, I’ll give it a go again once Phil releases the next version of his Rest module, I’m sure this will get solved somewhere along the line. Have set debug message to Superadmin so I can still check them 😊

       
eguystephens's avatar
eguystephens
90 posts
15 years ago
eguystephens's avatar eguystephens

E-man,

I have the same issue. I exchanged a couple e-mails with Phil and now have everything working except I still get a warning:

“Severity: Warning

Message: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set

Filename: libraries/Curl.php

Line Number: 248”

Is this why you turned off error reporting? How did you do this?

Thanks!

Guy

       
eguystephens's avatar
eguystephens
90 posts
15 years ago
eguystephens's avatar eguystephens

Ok I found it in ExpressionEngine under Admin (Output and Debugging Preferences) - I thought it was something I needed to change in php.ini.

Hope Phil has a fix soon!

Guy

       
e-man's avatar
e-man
1,816 posts
15 years ago
e-man's avatar e-man

You beat me to it 😊 Here’s hoping this gets solved in a coming version, this really is a useful Module.

       
Steve Hurst's avatar
Steve Hurst
36 posts
15 years ago
Steve Hurst's avatar Steve Hurst

It seems I’m unable to use this module on EngineHosting at the moment. Has there been any progress on a fix or workaround? Any of my REST requests result in what seems like a forward to the REST request URL, instead of data being piped into the template. With error reporting on, I get:

A PHP Error was encountered Severity: Warning Message: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set Filename: libraries/Curl.php Line Number: 248

And

Fatal error: Call to undefined function json_decode() in /**********/expressionengine/third_party/rest/pi.rest.php on line 409

Seems like this open_basedir setting issue on EngineHosting keeps coming up again and again…

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.