www.webdeveloper.com
Results 1 to 4 of 4

Thread: Using fsockopen and fread (Zend Cert)

  1. #1
    Join Date
    Apr 2006
    Posts
    246

    Question Using fsockopen and fread (Zend Cert)

    Hey all,

    I have came across this during my Zend Cert study, can anyone advise?

    Q: What is wrong with the following code snippet? Assume default configuration values apply.

    PHP Code:
    <?php
    $fp 
    fsockopen('www.php.net'80);
    fwrite($fp"GET / HTTP/1.0\r\nHost: www.php.net\r\n");
    $data fread($fp8192);
    ?>
    Answers (Choose 1):
    The request is blocking and may cause fread() to hang
    The HTTP request is malformed
    This script should be re-written using fgets() instead of fread()
    The request is non-blocking and fread() may miss the response
    You cannot use fwrite() with fsockopen()

    Many thanks,
    Picco

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    The request is missing its closing \r\n and as such is malformed.

  3. #3
    Join Date
    Apr 2006
    Posts
    246
    Should there be a double \r\n at the end of the request?

    PHP Code:
    fwrite($fp"GET / HTTP/1.0\r\nHost: www.php.net\r\n\r\n"); 
    ?

  4. #4
    Join Date
    Nov 2008
    Posts
    2,477
    Yes. This is what distinguishes the end of the request from a new line.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles