duaedf6509 2014-11-05 07:05
浏览 46
已采纳

Php crontab教程问题

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.

  • 写回答

1条回答 默认 最新

  • doudu9148 2014-11-05 10:19
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办