Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get maximum length of this function socket_recv() in PHP

Tags:

php

sockets

if(socket_recv ( $sock , $buf , 2045, MSG_WAITALL ) === FALSE)
{
    $errorcode = socket_last_error();
    $errormsg = socket_strerror($errorcode);        
    die("Could not receive data: [$errorcode] $errormsg <br>");
}
echo $buf;

from the function above it doesn't show full message, so I tried to get the maximum length of variable $buf like this

socket_recv ( $sock , $buf , strlen($buf), MSG_WAITALL )

but not work. please kindly help me

thx and regards,

like image 514
NoNo Avatar asked Oct 07 '22 14:10

NoNo


1 Answers

you should receive the response with a loop

$received;
while(socket_recv($sock, $buf, 1024, 0) >= 1)
{
    $received .= $buf;
}
like image 140
Lyle Malik Avatar answered Oct 10 '22 01:10

Lyle Malik