Sergey Scopin
Sergey Scopin

Reputation: 2245

Php crontab tutorial issues

Actually this is continue of Some try catch issue with php question. I'm using tutorial to create class for editing crontab. I have a file with class:

<?php
  Class Ssh2_crontab_manager 
  {
    private $connection;
    private $path;
    private $handle;
    private $cron_file;
    function __construct($host=NULL, $port=NULL, $username=NULL, $password=NULL)
    {
      $path_length    = strrpos(__FILE__, "/");
      $this->path      = substr(__FILE__, 0, $path_length) . '/';
      $this->handle    = 'crontab.txt';
      $this->cron_file = "{$this->path}{$this->handle}";

      try
      {
        if ((is_null($host)) || (is_null($port)) || (is_null($username)) || (is_null($password))) 
          throw new Exception("Please specify the host, port, username and password!");
        /*$this->connection = @ssh2_connect($host, $port);
        if ( !$this->connection)
          throw new Exception("The SSH2 connection could not be established.");

        $authentication = @ssh2_auth_password($this->connection, $username, $password);
        if ( !$authentication) 
          throw new Exception("Could not authenticate '{$username}' using password: '{$password}'.");*/    
      }
      catch (Exception $e)
      {
        echo $e;
      }
    }    
  }
?>

And a file where I use it:

<?php
  include './lib/Ssh2_crontab_manager.php';
  $crontab = new Ssh2_crontab_manager('host', '22', 'user', 'pass');
  echo 'WORKS';
?>

And again it says WORKS now, but if I uncomment string it doesn't says nothing. Now I use code from the end of step, so I don't repeat mistake I get in previous question. libssh2 was installed, may be problem that it wasn't successfully installed? How can I check it.

Edit: from phpinfo() libSSH Version libssh2/1.4.2
UPDATE

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
//include './lib/Ssh2_crontab_manager.php';
//$crontab = new Ssh2_crontab_manager('host', '22', 'user', 'pass');
echo "WORKS";
    $connection = ssh2_connect('host','22'); //new variable ...not needed this class
    /*if ( !$connection)
    { 
        echo "The SSH2 connection could not be established.";
    }
    else
    {
        echo"OK";
    }*/
    echo "OK?";
    $authentication = @ssh2_auth_password($connection, 'user', 'pass');
?>

Now I test it like this, code still stucks on ssh2_connect.

Upvotes: 0

Views: 397

Answers (1)

Riad
Riad

Reputation: 3850

Seems you are having timeout on your script. Check ssh connection PHP BUG here. Try to set a time limit to your script OR edit php.ini for max_execution_time.

You can use SSH API to make it work.

Upvotes: 1

Related Questions