Thursday, May 05, 2005

Need Some PHP Help

Is there a limitation to man's knowledge?

For all the hard work I have done to try finishing the PHP program, it seems that everything that I have tried doesn't work. Even I have tried consulting a few boards and communities in the internet, but to no avail, their suggestions won't work on my program either. There is still one more way to go, that is to consult my friend who works in a company that have ever made exactly what program I'm working on right now. But since today is a holiday in rememberance of the Ascension of Christ, I have to wait until tomorrow to see what I can do and whether my friend can be of any help. The scripting is already okay, so the problem must lie on my network settings (DNS resolution - not working for the PHP's gethostbyname internal function of the fsockopen function) or my Apache server settings.

For you who understand PHP, here is the test code I've been trying (I am going to develop a script for sending mass-SMS messages by using GET function to access the SMS server but right now I'm just trying to route it to my localhost)...

$host = "http://127.0.0.1";
$page = "/index.php";
$fp = fsockopen("$host", 80, &$errno, &$errdesc, 30);
if ( ! $fp )
{ die ( "Couldn't connect to $host:\nError: $errno\nDesc: $errdesc\n" ); }

$request = "GET $page HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
$request .= "Connection: Close";
fputs ( $fp, $request );
while ( ! feof( $fp ) )
{ $page[] = fgets( $fp, 1024 ); }
fclose( $fp );print "the server returned ".(count($page))." lines!";

And here are the error messages I received:

Warning: fsockopen(): php_network_getaddresses: gethostbyname failed in test.php on line 4

Warning: fsockopen(): unable to connect to http://127.0.0.1:80 in test.php on line 4
Couldn't connect to http://127.0.0.1: Error: 0 Desc: The operation completed successfully.

Can anyone help me fix this problem?
I think I have done it as it is written in the PHP manual (http://php.net/fsockopen), so if there are some mistakes in the code please do point out them and tell me about it.