PHP soket bağlantısı optimizasyon

0 Cevap php

Ben her şeyi daha hızlı olur bir kabuk komutları çalıştırdığınızda php yuva performans kullanarak komutları çalıştırdığınızda Ben, ancak, telnet kullanan bir API ile bu bağlantıyı yapıyorum ölçüde düşer. Bazı kod misconceived yaşıyorum?

/ **  
* Tries to make the connection to the server specified in the constructor, if the connection is made returns TRUE  
* Otherwise FALSE.  
* @Return boolean  
*/  
public function connect() {  

    try {  
        $stream = fsockopen($this->getHost(), $this->getPort(), $errno, $errstr, $this->getTimeOut());  

        $this->setStream($stream);  

        return true;  
    } catch (ErrorException $e) {  
        echo $e->getMessage();  
        return false;  
    } catch (Exception $e) {  
        echo $e->getMessage();  
        return false;  
    }  
}  

/ **
* Runs the specified command in $command at voipzilla's API through a socket connection.  
* @See $this-> connect ()  
* @Param string $command  
* @Param int $nl number of new lines (Enter) after the command   
* @Param boolean $command Sets the command clause will be added to the specified command  
* @Return string coming API's response API  
* /  
public function runCommand($command, $nl=4, $commandClause=true) {  
        //response  
        $response = null;  
        //
        $login = "login " . $this->getLogin() . "\n";  
        $login .= "password " . $this->getPassword() . "\n\n";  

        if ($commandClause) {  
            $command = "command " . $command;  
        }  

        $command = $login . $command;  

        for ($i = 1; $i <= $nl; $i++) {  
            $command .= "\n";  
        }  

        if(!$this->connect()){exit(0);}  

        fwrite($this->getStream(), $command);  

        while (!feof($this->getStream())) {  
            $response .= fgets($this->getStream(), 128);  
        }  

        return $response;  
}

0 Cevap