Php crontab教程问题

时间:2014-11-05 07:05:01

标签: php cron crontab

实际上这是Some try catch issue with php问题的继续。我正在使用tutorial创建用于编辑crontab的类。 我有一个类的文件:

<?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;
      }
    }    
  }
?>

我使用它的文件:

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

现在又说它工作了,但是如果我取消注释字符串它就什么都不说。现在我使用步骤结束时的代码,所以我不会重复上一个问题中的错误。安装了libssh2,可能是它没有成功安装的问题?我怎么检查呢。

修改: 来自phpinfo() libSSH版本libssh2 / 1.4.2
更新

<?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');
?>

现在我像这样测试它,代码仍然停留在ssh2_connect上。

1 个答案:

答案 0 :(得分:1)

似乎你的脚本超时了。检查ssh连接PHP BUG here。尝试为脚本设置时间限制或编辑php.ini以获取max_execution_time。

您可以使用SSH API使其正常工作。

相关问题