WordPress and File Get-Contents

WordPress and File Get-Contents

Posted by: Scoop
Posted on: 2008-05-25 21:12:00

Yes, I don't know PHP, so I'm sure that's the first problem. heh.. I'm trying to use a simple PHP script to pull in some content from another site of mine, and I've learned that Dreamhost prevents this command, and recommends using Curl (whatever that is!).

So I did that, but everytime I add the line of code, and update my template, I get an error that says:

Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

And when I remove the code, or add anything OTHER than this code, it works fine. So every time I add the code, it's a prob. Here's the code I'm using, as recommended via Dreamhost:

<?php
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://www.example.com');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);

// display file
echo $file_contents;
?>

Weird. Any help?



Re: WordPress and File Get-Contents

Posted by: patricktan
Posted on: 2008-05-25 21:24:00

Let's first try to increase timeout time

$timeout = 30;

Re: WordPress and File Get-Contents

Posted by: sdayman
Posted on: 2008-05-25 21:24:00

I get the same error when I incorporate PHP code in my Geeklog site's Static Pages. Dunno what the problem is, so I stopped doing it. I ended up manually adding it into the database via phpMyAdmin. Maybe someone knows why this happens.

-Scott

Re: WordPress and File Get-Contents

Posted by: scjessey
Posted on: 2008-05-26 06:12:00

If the site you are accessing is on the same DreamHost account (just a different domain), you do not need to use cURL. You can use file_get_contents() with an absolute (relative from root) path:

$data = file_get_contents("/home/username/domainfolder/path/to/file.php");

-- si-blog --

Re: WordPress and File Get-Contents

Posted by: sdayman
Posted on: 2008-05-26 06:38:00

That could be a handy workaround, but cURL seems to be necessary for my grab of:
http://www.mydomain.com/gallery/index.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_maxSize=400&g2_show=none

/gallery/ is a PHP-level rewrite to /gallery2/, and I'm not sure how well the file_get_contents will handle the PHP flags.

-Scott

Tags: maintenance downtimedreamhostphp scriptprob