We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

PHP Fatal error: Class 'Phalcon\DI\FactoryDefault\CLI' not found

Hello,

I have an ubuntu 13.10 machine with Phalcon 1.25 installed The web application using Phalcon runs fine. For some bulk operations I have develop some cli scripts. This cli scripts are working on my local Imac with also Phalcon 1.25 installed. running these scripts on my Ubuntu 13.10 machine give stye following error:

PHP Fatal error: Class 'Phalcon\DI\FactoryDefault\CLI' not found

my code starts with:

use Phalcon\DI\FactoryDefault\CLI as CliDI,
    Phalcon\CLI\Console as ConsoleApp,
    Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter,
    Phalcon\Mvc\Model\Manager;

define('VERSION', '1.0.0');
$di=new CliDI();

The error refers to line 8, where this line is:

$di= new CliDI():

My question is: Is there a workaround to solve this



8.1k
edited Oct '14

Your script is work

class Phalcon\DI\FactoryDefault\CLI#1 (3) {
  protected $_services =>
  array(10) {
    'router' =>
    class Phalcon\DI\Service#23 (4) {
      protected $_name =>
      string(6) "router"
      protected $_definition =>
      string(18) "Phalcon\CLI\Router"
      protected $_shared =>
      bool(false)
      protected $_sharedInstance =>
      NULL
    }
    'dispatcher' =>
    class Phalcon\DI\Service#24 (4) {
      protected $_name =>
      string(10) "dispatcher"
      protected $_definition =>
      string(22) "Phalcon\CLI\Dispatcher"
      protected $_shared =>
      bool(false)
      protected $_sharedInstance =>
      NULL
    }
    'modelsManager' =>
    class Phalcon\DI\Service#25 (4) {
      protected $_name =>
      string(13) "modelsManager"
      protected $_definition =>
      string(25) "Phalcon\Mvc\Model\Manager"
      protected $_shared =>
      bool(false)
      protected $_sharedInstance =>
      NULL
    }
    'modelsMetadata' =>
    class Phalcon\DI\Service#26 (4) {
      protected $_name =>
      string(14) "modelsMetadata"
      protected $_definition =>
      string(33) "Phalcon\Mvc\Model\Metadata\Memory"
      protected $_shared =>
      bool(false)
      protected $_sharedInstance =>
      NULL
    }
    'filter' =>
    class Phalcon\DI\Service#27 (4) {
      protected $_name =>
      string(6) "filter"
      protected $_definition =>
      string(14) "Phalcon\Filter"
      protected $_shared =>
      bool(true)
      protected $_sharedInstance =>
      NULL
    }
    'escaper' =>
    class Phalcon\DI\Service#28 (4) {
      protected $_name =>
      string(7) "escaper"
      protected $_definition =>
      string(15) "Phalcon\Escaper"
      protected $_shared =>
      bool(true)
      protected $_sharedInstance =>
      NULL
    }
    'annotations' =>
    class Phalcon\DI\Service#29 (4) {
      protected $_name =>
      string(11) "annotations"
      protected $_definition =>
      string(34) "Phalcon\Annotations\Adapter\Memory"
      protected $_shared =>
      bool(true)
      protected $_sharedInstance =>
      NULL
    }
    'security' =>
    class Phalcon\DI\Service#30 (4) {
      protected $_name =>
      string(8) "security"
      protected $_definition =>
      string(16) "Phalcon\Security"
      protected $_shared =>
      bool(true)
      protected $_sharedInstance =>
      NULL
    }
    'eventsManager' =>
    class Phalcon\DI\Service#31 (4) {
      protected $_name =>
      string(13) "eventsManager"
      protected $_definition =>
      string(22) "Phalcon\Events\Manager"
      protected $_shared =>
      bool(true)
      protected $_sharedInstance =>
      NULL
    }
    'transactionManager' =>
    class Phalcon\DI\Service#32 (4) {
      protected $_name =>
      string(13) "eventsManager"
      protected $_definition =>
      string(37) "Phalcon\Mvc\Model\Transaction\Manager"
      protected $_shared =>
      bool(false)
      protected $_sharedInstance =>
      NULL
    }
  }
  protected $_sharedInstances =>
  NULL
  protected $_freshInstance =>
  bool(false)
}

Check your installation. And check extension Phalcon is enabled.

The Phalcon installation is working fine. I have no problems with the web interface that uses Phalcon too. Every other Phalcon class can't be found when I access it from command line. The only different thing is that I use a different ssh port (not port 22)



8.1k

I tried your script on virtual server over ssh :

 ssh [email protected]
[email protected]'s password: 
Last login: Sat Jan 18 17:45:28 2014 from 172.16.0.1
archv|~$ cd inbox/
archv|inbox$ php di.php
object(Phalcon\DI\FactoryDefault\CLI)#1 (3) {
  ["_services":protected]=>
  array(10) {
    ["router"]=>
    object(Phalcon\DI\Service)#23 (4) {
      ["_name":protected]=>
      string(6) "router"
      ["_definition":protected]=>
      string(18) "Phalcon\CLI\Router"
      ["_shared":protected]=>

Something is wrong with Ubuntu. I use Archlinux.



8.1k

Did you installed php5-cli? If not, install it.

Yes I have php5-cli installed I have several other php5 scripts running fine under command line. I will try a VM with another linux to check if it's an ubuntu issue On Mac OSX everything works fine.



8.1k

Try to compare the setting of PHP (cli) in both systems.

I rather similar installation under Arch Linux works fine. It seems really an ubuntu issue.

Hi, in ubuntu 13.x you got to enable the extension in the different PHP Environments seperately. This can easily be done with php5enmod which creates symlinks for each extension from the environments conf.d directory in /etc/php5/xxxx to the /etc/php5/conf.d directory. Have a look into man php5enmod.

datenarbeit , how to solve this in ubuntu ?

I am using Ubuntu 12.04 , but it also not working. Phalcon is working fine , just not working , when use with cli.



632
Accepted
answer

maybe you placed "extension=phalcon.so" in /etc/php5/apache3/php.ini? it you had an /etc/php5/conf.d/phalcon.ini with "extension=phalcon.so" in it, everything should work fine on command line.

Thanks datenarbeit. It works.