mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
Possible workaround for some PHP bug
This commit is contained in:
parent
7ecac019a9
commit
aa992684ba
@ -24,10 +24,6 @@ namespace pocketmine\command;
|
|||||||
use pocketmine\Thread;
|
use pocketmine\Thread;
|
||||||
|
|
||||||
class CommandReader extends Thread{
|
class CommandReader extends Thread{
|
||||||
|
|
||||||
public $stream;
|
|
||||||
/** @var resource */
|
|
||||||
private $fp;
|
|
||||||
private $readline;
|
private $readline;
|
||||||
|
|
||||||
/** @var \Threaded */
|
/** @var \Threaded */
|
||||||
@ -35,17 +31,15 @@ class CommandReader extends Thread{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Threaded $threaded
|
* @param \Threaded $threaded
|
||||||
* @param string $stream
|
|
||||||
*/
|
*/
|
||||||
public function __construct(\Threaded $threaded, $stream = "php://stdin"){
|
public function __construct(\Threaded $threaded){
|
||||||
$this->stream = $stream;
|
|
||||||
$this->buffer = $threaded;
|
$this->buffer = $threaded;
|
||||||
$this->start();
|
$this->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function readLine(){
|
private function readLine(){
|
||||||
if(!$this->readline){
|
if(!$this->readline){
|
||||||
$line = trim(fgets($this->fp));
|
$line = trim(fgets(fopen("php://stdin", "r")));
|
||||||
}else{
|
}else{
|
||||||
$line = trim(readline("> "));
|
$line = trim(readline("> "));
|
||||||
if($line != ""){
|
if($line != ""){
|
||||||
@ -73,12 +67,10 @@ class CommandReader extends Thread{
|
|||||||
|
|
||||||
public function run(){
|
public function run(){
|
||||||
$opts = getopt("", ["disable-readline"]);
|
$opts = getopt("", ["disable-readline"]);
|
||||||
if(extension_loaded("readline") and $this->stream === "php://stdin" and !isset($opts["disable-readline"])){
|
if(extension_loaded("readline") and !isset($opts["disable-readline"])){
|
||||||
$this->readline = true;
|
$this->readline = true;
|
||||||
}else{
|
}else{
|
||||||
$this->readline = false;
|
$this->readline = false;
|
||||||
$this->fp = fopen($this->stream, "r");
|
|
||||||
stream_set_blocking($this->fp, 1); //Non-blocking STDIN won't work on Windows
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$lastLine = microtime(true);
|
$lastLine = microtime(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user