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 unity从3D升级到urp管线,打包ab包后,材质全部变紫色
  • ¥50 comsol温度场仿真无法模拟微米级激光光斑
  • ¥15 上传图片时提交的存储类型
  • ¥15 Ubuntu开机显示器只显示kernel,是没操作系统(相关搜索:显卡驱动)
  • ¥15 VB.NET如何绘制倾斜的椭圆
  • ¥15 arbotix没有/cmd_vel话题
  • ¥20 找能定制Python脚本的
  • ¥15 odoo17的分包重新供应路线如何设置?可从销售订单中实时直接触发采购订单或相关单据
  • ¥15 用C语言怎么判断字符串的输入是否符合设定?
  • ¥15 通信专业本科生论文选这两个哪个方向好研究呀