This is an old revision of the document!
WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0
Return a single line from a file or stream, with optional size limit
This function works with different resource types. If no size is specified, it will keep reading from the file or stream until it reaches the end of the line (or the end of the file). For sockets and streams it will return characters until a line feed (LF) or carriage return (CR) is reached (it will wait until an entire line is received). If the optional size is specified and the line is longer than this size, the function will return only the number of characters specified.
$handle: Valid handle of a previously opened resource
$size: Optional limit to the number of bytes returned
Open a TCP connection to google.com and print the header for a search for the word 'test':
<pre><? $f=fsockopen("www.google.com",80,10); if ($f) { // send the request: $out = "GET /search?q=test HTTP/1.0\r\n"; $out = $out."Host: www.google.com\r\n"; $out = $out."Connection: Close\r\n\r\n"; fwrite($f,$out); print($out); // wait for and receive the header (multiple lines): $done=0; while (!$done) { $str=fgets($f); print($str+"\r\n"); if (strlen($str)==0) $done=1; } fclose($f); } ?></pre>
fread() - Return bytes from a file or stream
fwrite() - Write data to a file or stream
fsockopen() - Open an internet socket connection with optional timeout
fopen() - Open a file for reading or writing
f485open() - Open the RS-485 port at the specified baud rate and parity
fseropen() - Open the serial port at the specified baud rate with optional parameters
fclose() - Close a file, stream or socket
ftell() - Position the file pointer in an open file