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.

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

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效