取不到$buffer變量里面子串的位置,求解惑
<?php
namespace Workerman\Protocols;
use Workerman\Connection\TcpConnection;
class Msg
{
public static $EndSymbol = '__end__';
public static function input($buffer, TcpConnection $connection)
{
if (strlen($buffer) >= TcpConnection::$maxPackageSize) {
$connection->close();
return 0;
}
$pos = strpos($buffer, self::$EndSymbol);
if ($pos === false) {
return 0;
}
return $pos + 1;
}
/**
* Encode.
*
* @param string $buffer
* @return string
*/
public static function encode($buffer)
{
return $buffer . self::$EndSymbol;
}
/**
* Decode.
*
* @param string $buffer
* @return string
*/
public static function decode($buffer)
{
return substr($buffer, 0, strpos($buffer, self::$EndSymbol));
}
}