but $sockbr is only zero at end of file...
That's not necessarily true. Here's why:
The web server sends data into your socket's Receive Queue (RQ) buffer (max size is 8192 bytes). When mIRC detects that there is data to be read in from the socket, it fires the on SOCKREAD event.
The on SOCKREAD event reads data from the RQ into a variable. $sock($sockname).rq tells you how many bytes are currently queued up, waiting to be read. As you read the data into your variable, it's removed from the RQ. That means there is no set size for the amount of data waiting to be read. Indeed, your socket might very well get in more data while it's processing the current data.
If you don't do a loop in on SOCKREAD, the event gets retriggered; however, that's not as efficient as looping while you're already in the on SOCKREAD event since you might have to handle other events in the meantime before managing to make it back to the on SOCKREAD event).
Remember that it might very well take several on SOCKREAD events to get the entire file. This is because you might process all the data on the socket before the server sends you more data (more of the rest of the file). If your script processes it all, then $sockbr becomes 0 because there is no more data waiting to be read CURRENTLY...the server hasn't sent anymore yet.
If you are sockclosing the socket before all the data is read, then you miss out on everything past the first on SOCKREAD event...the rest of the file.
You don't really need to close the socket since the web server will terminate it remotely. Just keep reading till you get all the information in and let the socket close itself.
DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C