phpseclib SSH2:为什么我的命令不运行?

I'm trying to make a web interface for managing my Ubuntu hosted Minecraft server. I use screen in order to make the console re-accessible. I don't get why the following code does not work:



    $ssh->read('quadrplax@quadrplax-laptop:~$');
    $ssh->write("screen -rd
");
    $ssh->write("stop
");

Now, don't ask me why, but if I add in this useless code:



    $randid=rand(0, 1000000);
    $consolemsg=strval($randid);

    $ssh->read('quadrplax@quadrplax-laptop:~$');
    $ssh->write("screen -rd
"); // note the "
"
    $ssh->write("say Stopping server - ID:".$consolemsg."
");
    echo $ssh->read(" [INFO] [Minecraft-Server] [Server] Stopping server - ID:".$consolemsg);
    $ssh->write("stop
");

Then it will be able to get the screen session disconnected, but the page will then load for minutes before timing out. Sorry for how stupid this is, I can't find any good guides for phpseclib, they all are copies of the same guide and don't give any long examples. I have been able to get some things to work, for example my suspend code somehow works:



    $ssh->read('quadrplax@quadrplax-laptop:~$');
    $ssh->write("sudo pm-suspend
");
    $ssh->setTimeout(5);
    $output = $ssh->read('#[pP]assword[^:]*:|quadrplax@quadrplax-computer:~\$#', NET_SSH2_READ_REGEX);
    $ssh->write("FAKEPASSWORD
");

Sorry for formatting errors or anything, first time here. I had a hard time getting this post to submit. Can someone help me out with this?

Edit: Fixed a copy-paste error