All,
I am having trouble with an fsocket connection. I can use the code below without a hitch to grab the actual data. Were the problem lies is......I can only seem to read data from my device using FgetC. So it returns each character one by one because the other methods hang. I am ok with using this method but i would need to some how store each character returned and then make (combine) into one big string so I can manupulate later on. Now I know there are the functions of Socket_recv, which seems like what would be ideal to use. My device does not send a LF command but rather a carriage return only. Can someone post an example of socket_receive that accepts data until a carriage return is sent. I am not opening a file, this is data streaming from a device (ip-rs485). If this is not possible then can someone post an example of how to put the characters all in one string using the code below. Thanks so much!
$current_line = fgetc($fp);
while (!feof($fp)) {
// process current line
$current_line = fgetc($fp);
if($current_line === "\r") break;
echo $current_line;
}
fclose($fp);
Fsocket char/string
Moderator: General Moderators
Re: Fsocket char/string
Code: Select all
$line = '';
while (!feof($fp))
{
$current_line = fgetc($fp);
if($current_line === "\r") break;
$line .= $current_line;
}
fclose($fp);
echo $line;There are 10 types of people in this world, those who understand binary and those who don't
Re: Fsocket char/string
What if you try using fgets after
Code: Select all
ini_set("auto_detect_line_endings", true);
stream_set_blocking($fp, 0);-
mrcastrovinci
- Forum Newbie
- Posts: 3
- Joined: Fri Sep 17, 2010 3:42 pm
Re: Fsocket char/string
VladSun wrote:Code: Select all
$line = ''; while (!feof($fp)) { $current_line = fgetc($fp); if($current_line === "\r") break; $line .= $current_line; } fclose($fp); echo $line;
THIS WORKS PERFECTLY!!!! Thank you so much!
-
mrcastrovinci
- Forum Newbie
- Posts: 3
- Joined: Fri Sep 17, 2010 3:42 pm
Re: Fsocket char/string
tasairis wrote:What if you try using fgets afterCode: Select all
ini_set("auto_detect_line_endings", true); stream_set_blocking($fp, 0);
tasairis wrote:ini_set("auto_detect_line_endings", true);
stream_set_blocking($fp, 0);
Thanks for the reply. I tried this and it just terminates the socket right away no data received. Weird.....Im not sure why. Any ideas?