fsockopen fails to connect to a valid URL.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aswathip
    New Member
    • Jan 2009
    • 16

    fsockopen fails to connect to a valid URL.

    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.fsocko pen]: unable to connect to alertbox.in:80
    (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:
    Code:
                                    $fp = fsockopen("alertbox.in", 80);
    		if (!$fp) 
    		{
    		   echo "$errstr ($errno)<br />\n";
    		} 
    		else 
    		{
    		   // $out = "GET / HTTP/1.1\r\n";
    		   // $out .= "Host: $host\r\n";
    		   // $out .= "Connection: Close\r\n\r\n";
    		   $out .=$host."?".$request."\r\n";
    		   echo $out;
    		   
    		   fwrite($fp, $out);
    		   while (!feof($fp)) 
    		   {
    			   echo fgets($fp, 128);
    		   }
    		   fclose($fp);
    		}
    can anybody please help me out for this problem? Thanks in advance.
    Last edited by Atli; Jan 19 '09, 10:10 AM. Reason: Changed the thread title.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    I tried your code on my test server and it seemed to work fine.
    I got this output when I executed it:
    Code:
    ?
    <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?

    Comment

    • aswathip
      New Member
      • Jan 2009
      • 16

      #3
      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

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        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 :]

        Comment

        • aswathip
          New Member
          • Jan 2009
          • 16

          #5
          Hi,

          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.

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            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_conten ts function or the CURL functions.
            Like, for example:
            [code=php]
            <?php
            $url = "http://www.example.com ";
            if($response = file_get_conten ts($url)) {
            echo "Success!<pre>" , $response, "</pre>";
            }
            else {
            echo "Failed!";
            }
            ?>[/code]

            Comment

            Working...