0

I want to put time interval for sftp connection in php. If the time exceeds 60 seconds to connect to it, then it should be disrupted and exception is to be handled. I don't really know how to do it.

I tried to do:

set_time_limit(60)

But, it does not work.

I want to put time limit in this function:

private function __connectSFTP()
    {
        $this->sftp = new Net_SFTP($this->host, 22);


        if (!$this->sftp->login($this->user, $this->password))
        {
            return $this->_requestErrorMessage('could not connect to server');

        } else
        { 
            return $this->__downloadFile();
        }


    }

I also tried to do:

$toTime = time()+60;

while(time() != $toTime){
//connection code
}

But, sadly It doesn't work at all.

I would be grateful if anybody could suggest me what can I do.

floriank
  • 25,546
  • 9
  • 42
  • 66
nirazlatu
  • 983
  • 8
  • 18

0 Answers0