Forum Moderators: coopster

Message Too Old, No Replies

cgi error

         

jackvull

3:16 pm on Jun 29, 2006 (gmt 0)

10+ Year Member



Hi

I have a script which attempts to run an external script on another server. For testing reasons it's 127.0.0.1

$url = "http://127.0.0.1/htdocs/UpdateCount.php?aID=".$aID;
$needle = 'Count:';
$contents = file_get_contents($url);
echo $contents;
if(strpos($contents, $needle)!== false) {
echo '<br />found';
} else {
echo '<br />not found';
}

I get the following error when I run it:
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

PHP version 4.4.2
IIS win2k

Any ideas why?
I've seen various bug reports for this error but none are related to file_get_contents and I'm not doing anything strange in the external script. It just runs a DB query and echo's it to the page.

eelixduppy

3:21 pm on Jun 29, 2006 (gmt 0)



Are you sure you don't want the url to be:

$url = "http://127.0.0.1/UpdateCount.php?aID=".$aID;

Also, why don't you execute the query from your own script?

jackvull

3:32 pm on Jun 29, 2006 (gmt 0)

10+ Year Member



For testing, yeah, it definitely needs the htdocs in there. That's just the way my dev server is.
I've tested that script by using the url directly in a browser and it outputs some data.

The reason I can't use it directly, is that this script (running the file_get_contents) will actually be run on a different server. So, I'm running it on Server 2, it's supposed to retrieve a database value from server 1 and then use that in some of its variables.

I can't access server 1's DB directly cos of their security setup.

mcavic

3:53 pm on Jun 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I assume that you've tried running the UpdateCount.php script directly from your web browser. And tried a 'hello world' script in place of the script that's using file_get_contents.

I ran the following, and it worked fine under Apache.

<?php

$aID = "0";
$url = "http://localhost/index.php?id=".$aID;
$needle = 'Count:';
$contents = file_get_contents($url);
echo $contents;
if(strpos($contents, $needle)!== false) {
echo '<br />found';
} else {
echo '<br />not found';
}

jackvull

3:59 pm on Jun 29, 2006 (gmt 0)

10+ Year Member



Yeah, it works fine when I comment out the file_get_contents section. It just echos the url or whatever I get it to do.
It's starnge because even with the cgi error I can see that the external script was accessed because the database fields change.

I'll try it on Apache later and see if that makes a difference.

eelixduppy

4:20 am on Jun 30, 2006 (gmt 0)



It seems like it may be a problem with your "remote" script. I would also take a peek there to see if you can identify what's causing this. I'm assuming that this error message came from that script when you received its contents?

jackvull

11:13 am on Jul 3, 2006 (gmt 0)

10+ Year Member



Thanks for all the help.
It works fine on apache.
Must have been an IIS problem.