0

I'm trying to create a class for work with crontab in php. I used this tutorial.

I've installed libssh2 but as you can see there is no work with it yet. So I have a file Ssh2_crontab_manager.php on my server. Here it's content:

<?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!");
                }
                catch
                {

                }*/
            }


      }
?>

And here is noReplyCrontab.php where I try to use this class:

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

If I run it now, it says 'works', but if I uncomment try/catch block it shows just white screen, so I suppose that there is some mistake. Any one can show it to me?

2 Answers 2

3

Your code says

 catch
 {

 }

But catch What?

You have to provide that value to catch clause

catch (Exception $e)
{
         //now it will work fine
}

Manual

Sign up to request clarification or add additional context in comments.

2 Comments

I'll accept your answer soon. Just copied it from tutorial
@SergeyScopin That is because you didn't go down the page far enough. It reads catch (Exception $e) { $this->error_message($e->getMessage()); } - it's a step-by-step, and the 1st and 2nd do not, but the 3rd does.
1

try this

try
{
    if (true) throw new Exception("Please specify the host, port, username and password!");
}
catch(Exception $e)
{
    echo $e->getMessage();
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.