By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,897 Members | 1,603 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,897 IT Pros & Developers. It's quick & easy.

fsockopen fails to connect to a valid URL.

P: 16
I am new to sockets and fsockopen(). I am trying to send SMS using a gateway. But the fsockopen always shows the following error.

Warning: fsockopen() [function.fsockopen]: unable to connect to
(A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\wamp\www\pro\SendSMS.php on line 45

Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\pro\SendSMS.php on line 45

Th code Used is:
Expand|Select|Wrap|Line Numbers
  1.                                 $fp = fsockopen("", 80);
  2.         if (!$fp) 
  3.         {
  4.            echo "$errstr ($errno)<br />\n";
  5.         } 
  6.         else 
  7.         {
  8.            // $out = "GET / HTTP/1.1\r\n";
  9.            // $out .= "Host: $host\r\n";
  10.            // $out .= "Connection: Close\r\n\r\n";
  11.            $out .=$host."?".$request."\r\n";
  12.            echo $out;
  14.            fwrite($fp, $out);
  15.            while (!feof($fp)) 
  16.            {
  17.                echo fgets($fp, 128);
  18.            }
  19.            fclose($fp);
  20.         }
can anybody please help me out for this problem? Thanks in advance.
Jan 19 '09 #1
Share this Question
Share on Google+
5 Replies

Expert 5K+
P: 5,058

I tried your code on my test server and it seemed to work fine.
I got this output when I executed it:
Expand|Select|Wrap|Line Numbers
  1. ?
  2. <center><p><b>Your Pointing Was Successful, Please contact your administrator For Activation.</b></p></center>
Could it be that your server is somehow blocking your connection to this site?
Jan 19 '09 #2

P: 16
thanks for your reply.
we r trying find it out.
We got the same output now. But SMS is not getting send. All Admin seetings are correct. Can u please help this further?

thanks once again for that fast reply
Jan 19 '09 #3

Expert 5K+
P: 5,058
Seems that the connection is made and the request is being processed.

Now you just need to find out what you have to send to the server so the SMS gets sent and make sure that is what you are sending.

Somehow I doubt what you are sending in that code is what they want :]
Jan 19 '09 #4

P: 16

In the code fragment there is one statement that prints the url being accessed.

echo $out;

This prints that URL correctly. When I copy that URL and directly give it in the address bar SMS is getting send immediately.

Thank you.
Jan 20 '09 #5

Expert 5K+
P: 5,058
Ok, so the $out variable is an URL you want to call?

If that is the case, then simply a socket and sending the URL is not the way to do this.If you open a socket like that, you would have to send an actual HTTP request, not just the URL.

To simply call an URL, you can use the file_get_contents function or the CURL functions.
Like, for example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $url = "";
  3. if($response = file_get_contents($url)) {
  4.   echo "Success!<pre>", $response, "</pre>";
  5. }
  6. else {
  7.   echo "Failed!";
  8. }
  9. ?>
Jan 20 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.