PHP network function fsockopen how to implement Socket link. Syntax: intfsockopen (stringhostname, intport, int [errno], string [errstr], int [timeout]); return value: integer function type: Network System Description: Current PHP network functionSyntax: int fsockopen (string hostname, int port, int [errno], string [errstr], int [timeout]);
Return value: integer
Function type: Network System Description: Currently, the PHP network function fsockopen provides two Socket data stream interfaces: AF_INET for Internet and AF_UNIX for Unix. When used on the Internet, the hostname and port parameters represent the URL and port numbers respectively. In UNIX, you can use IPC. the hostname parameter indicates the socket path and port is set to 0. The time out option that can be omitted indicates how long the connection is interrupted. After using this function, a file pointer is returned for the file function, including fgets (), fgetss (), fputs (), fclose (), and feof (). The errno and errstr parameters can also be omitted and used for error handling. Using this function, the block mode is used for processing. you can use set_socket_blocking () to convert it to the no-hold mode.
Example of using the PHP network function fsockopen. This example is used to simulate an HTTP connection.
-
- $fp = fsockopen("php.wilson.gs", 80, &$errno, &$errstr, 10);
- if(!$fp) {
- echo "$errstr ($errno)
n";
- } else {
- fputs($fp,"GET / HTTP/1.0nHost: php.wilson.gsnn");
- while(!feof($fp)) {
- echo fgets($fp,128);
- }
- fclose($fp);
- }
- ?>
Through the above example of using the PHP network function fsockopen, do readers have basically mastered the usage of this function?
Optional int fsockopen (string hostname, int port, int [errno], string [errstr], int [timeout]); return value: integer function type: network system description: current PHP network functions...