Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 22-05-2009
Member
 
Join Date: Oct 2008
Posts: 20
PHP fsockopen Functions

fsockopen — Open Internet or Unix domain socket connection

Quote:
resource fsockopen ( string $hostname [, int $port= -1 [, int &$errno [, string &$errstr [, float $timeout= ini_get("default_socket_timeout") ]]]] )
PHP supports targets in the Internet and Unix domains as described in List of Supported Socket Transports. A list of supported transports can also be retrieved using stream_get_transports().

The socket will by default be opened in blocking mode. You can switch it to non-blocking mode by using stream_set_blocking().
Reply With Quote
  #2  
Old 22-05-2009
Member
 
Join Date: Dec 2008
Posts: 65
Re: PHP fsockopen Functions

By default php.ini set the user_agent to ?PHP? which signifies that it?s the script that try to access the web server. Some web servers will refuse and don?t allow script to access and receive the date from the server.
Reply With Quote
  #3  
Old 22-05-2009
Member
 
Join Date: Oct 2008
Posts: 74
Re: PHP fsockopen Functions

sockopen() returns a file pointer which may be used together with the other file functions (such as fgets(), fgetss(), fwrite(), fclose(), and feof()). If the call fails, it will return FALSE

fsockopen() Example

PHP Code:
<?php
$fp 
fsockopen("www.example.com"80$errno$errstr30);
if (!
$fp) {
    echo 
"$errstr ($errno)<br />\n";
} else {
    
$out "GET / HTTP/1.1\r\n";
    
$out .= "Host: www.example.com\r\n";
    
$out .= "Connection: Close\r\n\r\n";
    
fwrite($fp$out);
    while (!
feof($fp)) {
        echo 
fgets($fp128);
    }
    
fclose($fp);
}
?>
Reply With Quote
  #4  
Old 22-05-2009
Member
 
Join Date: Dec 2008
Posts: 98
Re: PHP fsockopen Functions

fsockopen() Using UDP connection

PHP Code:
<?php
$fp 
fsockopen("udp://127.0.0.1"13$errno$errstr);
if (!
$fp) {
    echo 
"ERROR: $errno - $errstr<br />\n";
} else {
    
fwrite($fp"\n");
    echo 
fread($fp26);
    
fclose($fp);
}
?>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "PHP fsockopen Functions"
Thread Thread Starter Forum Replies Last Post
trim functions of VB Ram Bharose Software Development 5 31-12-2009 11:51 AM
SQL Scalar Functions Bhardwaj Software Development 5 15-12-2009 12:38 PM
How to call a C functions within PHP? Rixwel Software Development 3 05-09-2009 09:12 AM
Array Functions in PHP SuperXCM Software Development 2 26-03-2009 10:57 AM
Functions in PHP Gyan Guru Guides & Tutorials 3 13-12-2008 06:20 PM


All times are GMT +5.5. The time now is 05:00 PM.