PHP network function Fsockopen How to implement socket link _php Tutorial

Source: Internet
Author: User
Tags network function
Syntax: int fsockopen (string hostname, int port, int [errno], string [errstr], int [timeout]);

return value: Integer

Function type: Network system content Description: At present PHP network function Fsockopen provides two Socket data flow interface, respectively for the Internet use of af_inet and Unix Af_unix. When used in the Internet situation, the parameters hostname and port respectively represent the URL and port number. In the UNIX scenario, the Ipc,hostname parameter is represented to the socket path, and port is configured to 0. The timeout option that can be omitted indicates how long it has been interrupted without a connection. After using this function, a file pointer is returned for use by the file function, including fgets (), FGETSS (), fputs (), fclose (), and feof (). Parameters errno and Errstr can also be omitted, mainly as error handling use. With this function, the shelve mode (blocking mode) is used, and the set_socket_blocking () can be converted to no-hold mode.

PHP Network function Fsockopen Use example, this example is used to simulate the HTTP connection.

 
 
    1. PHP
    2. $ FP = Fsockopen ("Php.wilson.gs", & $errno, & $errstr, 10);
    3. if (! $fp) {
    4. echo "$errstr ($errno) < BR > n ";
    5. } else {
    6. Fputs ($fp, "get/http/1.0nhost:php.wilson.gsnn");
    7. while (!feof ($fp)) {
    8. Echo fgets ($FP, 128);
    9. }
    10. Fclose ($FP);
    11. }
    12. ?>

Using the above PHP network function Fsockopen example, readers are not already able to grasp the basic function of the use of it?


http://www.bkjia.com/PHPjc/446295.html www.bkjia.com true http://www.bkjia.com/PHPjc/446295.html techarticle syntax: int fsockopen (string hostname, int port, int [errno], string [errstr], int [timeout]), return value: Type of integer function: Description of network system content: current P HP Network Functions ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.