Dreamhost, PHP Scripts and cURL

In an effort to teach myself basic programming, I have been playing around with stuff on my personal site. One thing I wanted to do was take the RSS feed from my blog and put headlines on the homepage of my site. I briefly considered trying to figure out how to do this myself, but quickly decided I would be better off just looking for an existing script that I could modify. I found a great PHP script (RSS2HTML) that seemed to fit my purpose perfectly. So I downloaded the script, customized it in TextWrangler, uploaded it to my Dreamhost server, tried to run it and…got the following error:

URL file-access is disabled in the server configuration

Well, this meant nothing to me. After a lot of research and trial and error, I found an article on the Dreamhost support wiki that says:

DreamHost has disabled the PHP option allow_url_fopen. This would normally allow a programmer to open, include or otherwise use a remote file using a URL, rather than a local file path.

I took this to mean that the script as written would not work on Dreamhost. Apparently the problem was the use of an ‘include‘ command in the script.

Here is the snippet I was trying to use:

include("http://www.example.com/script.php");

The alternative, according to this article, is to use cURL. Well, long story short, this solved the problem and now it works great. Here is the new code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/script.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);

You can see the final product here. 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: