Cli and Background process

I have cloned php-site as my reference to start phalcon project. It seems that I could not run php in /php-site/scripts/ directly both from browser and cli. I suppose these shall be run in background. What is the correct way to run these scripts? any example of this?



83.0k

Regarding the scripts on php-site, these are meant to build the database used as example, a better structure for scripts is available on Phosphorum: https://github.com/phalcon/forum/blob/master/scripts/send-notifications.php



1.4k

Thanks for the tips. However, still have some issues dealing with models.

I created project using devtools. When try to run cli command, it return errors below when i run <Models>::find()

0 [internal function]: Phalcon\DI->get('db', NULL)

1 [internal function]: Phalcon\DI->getShared('db')

2 [internal function]: Phalcon\Mvc\Model\Manager->getReadConnection(Object(Livescore\Models\League))

3 [internal function]: Phalcon\Mvc\Model->getReadConnection()

4 [internal function]: Phalcon\Mvc\Model\Query->_executeSelect(Array, NULL, NULL)

5 [internal function]: Phalcon\Mvc\Model\Query->execute(NULL, NULL)

6 /mnt/project/livescore/scripts/update-schedule.php(49): Phalcon\Mvc\Model::find()

7 /mnt/project/livescore/scripts/update-schedule.php(83): GetScheduleFeed->run()

Can someone give some advice?



83.0k

Can you please print the message related to the exception?

catch (Exception $e) {
   echo $e->getMessage();
   echo $e->getTraceAsString();
}


1.4k

Here you go..

Service 'db' wasn't found in the dependency injection container

0 [internal function]: Phalcon\DI->get('db', NULL)

1 [internal function]: Phalcon\DI->getShared('db')

2 [internal function]: Phalcon\Mvc\Model\Manager->getReadConnection(Object(Livescore\Models\League))

3 [internal function]: Phalcon\Mvc\Model->getReadConnection()

4 [internal function]: Phalcon\Mvc\Model\Query->_executeSelect(Array, NULL, NULL)

5 [internal function]: Phalcon\Mvc\Model\Query->execute(NULL, NULL)

6 /mnt/project/livescore/scripts/update-schedule.php(49): Phalcon\Mvc\Model::find()

7 /mnt/project/livescore/scripts/update-schedule.php(83): GetScheduleFeed->run()

8 {main}



83.0k


1.4k

Yes, I registered 'db' services in app/config/services.php and include it in cli-bootstrap.php Then I pass both $config & $di during __construct GetScheduleFeed()



83.0k

Do you have eaccelerator enabled?



1.4k

Nope, eAccelerator is not enabed

Do you use VirtualMachine? VirtualBox?



1.4k

FYI, I'm using Amazon EC2 Linux AMI release 2013.03 + RDS Mysql 5.6 Apache 2.4 & PHP 5.4.16

Ah, ok, I thinked about it because had problem with VirtualBox development, and SharedFolders. Updating via SharedFolder looked like Virtual Linux have no information about filesystem changes. And this bug is marked as notFix. https://www.virtualbox.org/ticket/10660

But in your case i don't know what could happen.



1.4k

Hmm... let me try with another box then ;)



1.4k

It still don't work for me in another box :(



83.0k

Can you post the relevant code that is not working?



1.4k

this is cli-bootstrap.php

<?php

/** * CLI Bootstrap */

errorreporting(EALL); settimelimit(0);

/** * Read the configuration */ $config = include DIR . "/../app/config/config.php";

$loader = new Phalcon\Loader();

/** * Include the loader */ require DIR . "/../app/config/loader.php";

$loader->register();

/** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new Phalcon\DI\FactoryDefault();

/** * Include the application services */ require DIR . "/../app/config/services.php";

and this is script i run

<?php

require 'cli-bootstrap.php'; define('FEEDURL', '<link>'); define('DAYS', 7);

try { $league = League::find(); var_dump($league); } catch(Exception $e) { echo $e->getMessage(); echo $e->getTraceAsString(); }

League is model created through DevTools