-
-
Save clue/11254932 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$buffer = ''; | |
$conn->on('data', function($data, $conn) use (&$buffer) { | |
$buffer .= $data; | |
// check to see if the buffer contains any line feeds (detect end of line) | |
while (false !== ($pos = strpos($buffer, PHP_EOL))) { | |
// get the first line from the buffer (up to the EOL) | |
$line = substr($buffer, 0, $pos); | |
// remove the line from the buffer (advance behind the EOL) | |
$buffer = (string)substr($buffer, $pos + strlen(EOL)); | |
// do something with $line | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment