503 on cURL


I’ve been having difficulties creating a random image rotator integrated with Gallery2. I’ve read the wiki, I know why the standard method doesn’t work, and so I’ve been trying to implement alternative methods. Currently the code I’m trying to use is:

<?php $ch = curl_init(); $timeout = 5; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, 'http://www.mad-science.org/Gallery/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); echo $file_contents; ?>

I insert this code into a template and attempt to update it, however, I get a 503 Error when I try to update the template. I’ve also pasted the code into a PHP file named rotator.php, and I get an output of “1”. What’s going on here?

Site: http://www.mad-science.org
PHP file: rotator.php


Can you show me the original code, before you tried to cuRLify it? If you are trying to reference images within your own gallery, I cannot see why you would need to use a complete URL (which means you don’t need cURL).

Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


Here is the code snippet which Gallery2 recommends:

External Image Block

Use a PHP block like the one shown below to include an image block in a PHP page outside of Gallery.

<?php @readfile('http://www.mad-science.org/Gallery/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title'); ?>

I’ve tried inserting that into one of my templates, however, it doesn’t return anything. When I visit the link being called in the readfile() in Firefox, the image shows up, but I just can’t get it displayed on my pages.

I am still rather curious as to why cURL seems to be unusable on DreamHost though, but I suppose at the moment, that is secondary relative to getting this random image block code to display.


Is mad-science.org your domain, or an external domain that you are trying to fetch data from? If it is your domain, change this:

<?php @readfile('http://www.mad-science.org/Gallery/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title'); ?> To this:

<?php @readfile($_SERVER['DOCUMENT_ROOT'].'/Gallery/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title'); ?>

I have no problems with cURL, although I have never used it with a query string.

If this doesn’t work, try looking at this discussion.

Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


Yeah, mad-science.org is my domain.

Here is the code that I’ve entered into the template:

<?php @readfile($_SERVER['DOCUMENT_ROOT'].'/Gallery/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title'); ?>

This is the output on the actual HTML page after I’ve rebuilt the index page to implement the changes:

Its as if the PHP is just being ignored.


I can’t think of anything else, sorry.

Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


Try removing the @ symbol from readfile and see if any errors are generated.
There is also a command to generate all errors that maybe hidden from display.



I’ve just implemented your suggestion, and I still get absolutely no output, even with:

<?php readfile($_SERVER['DOCUMENT_ROOT'].'/Gallery/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title'); error_reporting(E_ALL); ?>

No errors… Just blankness.

I’ve been testing out various alternative options for making a random image rotation script, but I keep running into the same roadblocks. For example, I can run trial.php
(http://www.mad-science.org/pivot/templates/trial.php), and successfully pull an image out of a directory using PHP, but when I try and include trial.php into another file, I get the directory path, but not the filepath outputted. It is rather frustrating. I’m really at a loss as to what the problem is.

I’ve been suspecting that this may have something to do with Pivot, the CMS that I’m using, but I’ve followed steps to ensure that the PHP is parsed prior to being processed by the CMS… I’ve posted a query on their forums, but so far, no reply.

Thanks for helping to track this down.

*Edit: I’ve just added the following to a new PHP file:

<?php readfile($_SERVER['DOCUMENT_ROOT'].'/Gallery/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title'); error_reporting(E_ALL); ?>

And it generates the following error:
Warning: readfile(/home/madpsi/mad-science.org/Gallery/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title): failed to open stream: No such file or directory in /home/.draconid/madpsi/mad-science.org/death.php on line 1


I just happened to run into the same problem, and recycled some code that worked. Here’s my code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “http://www.pmbc.org/gallery2/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_maxSize=400&g2_show=fullSize&g2_itemFrame=Shadow”);
curl_setopt($ch, CURLOPT_HEADER, 0);

I’m still trying to get the Shadow frame to work, though.



I just tried my original cURL code for the hell of it, and it works now. No more 503s. Go figure. :-/