3

I have a command line test script that runs locally OK, but when I try to run it on my host (Bluehost) through ssl (using Putty) it fails, but doesn't throw an error.

I've checked the error logs and there is nothing there to indicate a failure and I have turned on E_ALL errors there.

On my local wamp server this runs fine and outputs all the prompts:

1. environment imported
2. About to execute!
3. Got instance
4. Success
5. Finished executing!

When I run this over putty at my host it outputs only the first two lines. 1. environment imported 2. About to execute!

This is the script (joomla 3.4.5):

<?php
// Initialize Joomla framework
const _JEXEC = 1;
ini_set('display_errors', 1);
error_reporting(E_ALL);

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';

require_once JPATH_BASE . '/includes/framework.php';


echo "1. Environment imported\n";

class Test extends JApplicationCli
{
public function doExecute()
    {
         echo "4. Successful execution\n";
    }
}

echo "2. About to execute\n";

$test = JApplicationCli::getInstance('Test');
echo "3. Got instance\n";

$test->execute();
echo "5. Finished executing!\n";

?>

I have tried running this with different variations of the command line:

php jwjtest.php
php54s -c ~/public_html/php.ini ~/public_html/cli/jwjtest.php

I have also surrounded the line that executes 'getInstance' with 'try' and 'catch' but no error is caught.

Any help would be welcome. Thanks!

Note: I am posting this on the joomla stackexchange (I already tried the regular stackexchange, but this seemed to be a more relevant forum)

Note: I've tried triggering run time errors and they seem to work fine outside the cli class, but inside the doExecute method nothing happens (as if no code inside there is being executed), but something must be erroring out because the last echoe'd comment ('finished executing') never gets executed.

  • 1
    Have you check that php5-cli is installed? – jdog Oct 28 '15 at 19:42
  • Ahah. I've not done that - I have been running the command using something like: php jwjtest.php and also php54s -c php.ini jwjtest.php (which I use in a cron job) ... how do I run php5-cli or test for its availability? Thanks – user1104799 Oct 29 '15 at 0:54
  • Thanks ... that worked!! I used php54-cli to run the script and all was well ; much appreciated (I'm not sure how to mark a comment as answering the question on stackexchange) – user1104799 Oct 29 '15 at 1:02
  • will do! Thanks for posting the answer as you did (though in fact the issue wasn't that php5-cli wasn't installed , it was just that I was issuing the command php jwjtest.php instead of php54-cli jwjtest.php – user1104799 Oct 30 '15 at 4:01
4

Have you checked that php5-cli is installed?

If it's not installed, you can run the following in command line to install it:

apt-get install php5-cli

or

yum install php5-cli
  • 1
    What worked for me in the end was to run php54-cli directly. By using just 'php' I guess that I had been running the wrong version of php. – user1104799 Oct 30 '15 at 3:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.