Jonathan Posted October 16, 2014 Report Posted October 16, 2014 Is it possible to initialize all of blesta apps/models/etc in a script completely external to Blesta? So far I've found that I need to load the following files: require_once('../lib/init.php');require_once('../app/app_controller.php');require_once('../app/app_model.php'); Loader appears to be working properly also: Loader::loadModels($this, array("Clients","Accounts","Services","Packages","PackageGroups","PackageOptions","PackageOptionGroups","Companies")); If I then for example do a call to $this->Clients->getAll(); or something similar it works as expected and I can print_r the return array, but as soon as I make a call to anything needing to write data it just fails, we'll say $this->Clients->add() for example. I get no return, no errors, nothing. Quote
gutterboy Posted October 19, 2014 Report Posted October 19, 2014 Is it possible to initialize all of blesta apps/models/etc in a script completely external to Blesta? So far I've found that I need to load the following files: require_once('../lib/init.php'); require_once('../app/app_controller.php'); require_once('../app/app_model.php'); Loader appears to be working properly also: Loader::loadModels($this, array("Clients","Accounts","Services","Packages","PackageGroups","PackageOptions","PackageOptionGroups","Companies")); If I then for example do a call to $this->Clients->getAll(); or something similar it works as expected and I can print_r the return array, but as soon as I make a call to anything needing to write data it just fails, we'll say $this->Clients->add() for example. I get no return, no errors, nothing. Have you considered using the API? Quote
Jonathan Posted October 19, 2014 Author Report Posted October 19, 2014 Have you considered using the API? Yep, and it works, but I'm trying to speed things up. The overhead of API style (connect, execute, disconnect) is what I'm trying to work around now. Initializing the functionlity directly takes the connect and disconnect out of the equation which is what's really slowing me down at this point. This includes the "local" CLI API method as well. I'm hoping Cody or Tyson can let me know what element(s) I'm missing here as I know I'm close - gets work, posts just don't seem to do anything. Quote
Blesta Addons Posted October 19, 2014 Report Posted October 19, 2014 i don't make any test for that , but i think loding just the init.php file is enough . as from the init.php is loading all others library . have you enabled the Configure::errorReporting(1); in your blesta.php ? PauloV 1 Quote
Jonathan Posted October 19, 2014 Author Report Posted October 19, 2014 I thought it was enough too but only loading it threw undefined class errors everywhere whereas loading the other two files at least got get-style requests working. Yes, I've got full error reporting turned on everywhere. Quote
Cody Posted October 21, 2014 Report Posted October 21, 2014 You can use the CLI API to interact with models. You can also execute controllers via CLI: % php /path/to/blesta/index.php controller/action param1 param2 param3 This is how cron jobs are executed (e.g. php /path/to/blesta/index.php cron) You could create a plugin which would give you an environment to execute whatever you want via CLI: % php /path/to/blesta/index.php plugin/plugin_name/controller_name/action The above assume the following in /path/to/blesta/plugins/plugin_name/controller_name.php: <?php class ControllerName extends AppController { public function index() { echo "the default action"; } public function action() { echo "a different action"; } } PauloV 1 Quote
Jonathan Posted October 21, 2014 Author Report Posted October 21, 2014 You can use the CLI API to interact with models. You can also execute controllers via CLI: % php /path/to/blesta/index.php controller/action param1 param2 param3 This is how cron jobs are executed (e.g. php /path/to/blesta/index.php cron) You could create a plugin which would give you an environment to execute whatever you want via CLI: % php /path/to/blesta/index.php plugin/plugin_name/controller_name/action The above assume the following in /path/to/blesta/plugins/plugin_name/controller_name.php: <?php class ControllerName extends AppController { public function index() { echo "the default action"; } public function action() { echo "a different action"; } } Yeah I've tried the CLI API calls but unfortunately the connect/disconnect overhead that goes along with each call is still my biggest slowdown. I've got the actualy HTTP overhead to such a minimum by doing things locally with a good web-server configuration that the difference in the two in my benchmarks was negligible which is why I was hoping to just initiate Blesta directly in my code as to avoid this overhead. EDIT: Just noticed that your calls are bypassing the API and going for a direct execution of the methods. What sort of overhead does calling to the API have via command line versus calling directly like this? Will this get rid of a noticeable amount when doing tens of thousands of calls? Quote
Blesta Addons Posted October 22, 2014 Report Posted October 22, 2014 This command can only be called locally . So is not workable in remote host, that reason the API EXIST . PauloV 1 Quote
Jonathan Posted October 22, 2014 Author Report Posted October 22, 2014 This command can only be called locally . So is not workable in remote host, that reason the API EXIST . Right - I'm working locally. Figured I'd try throwing all of this into a plugin so I can make the calls locally to the core Models (the ones at http://source-docs.blesta.com/package-blesta.app.models.html) and it seems I'm in the same boat as trying to initialize Blesta externally. Any calls to get data work great. Any calls that write data such as lets say PackageGroups->add or Packages->add, etc. fail with absolutely 0 return or errors. Even nothing useful from strace. They literally just seem to do nothing. Quote
Jonathan Posted October 22, 2014 Author Report Posted October 22, 2014 Well I got it figured out. The problem is/was that the api expects the input arrays to be in the format of $vars 'vars' var1 var2 Whereas internally the calls are expected to be like this: $vars var1 var2 Basically drop the 'vars' array which contains the values for the API and set the values directly on the parent array passed to the method. A bit of clarification in the documentation could certainly save folks some time. This got me both starting using the API as well as trying to convert from the API to internal for speed. Quote
Blesta Addons Posted October 22, 2014 Report Posted October 22, 2014 Well I got it figured out. The problem is/was that the api expects the input arrays to be in the format of $vars 'vars' var1 var2 Whereas internally the calls are expected to be like this: $vars var1 var2 Basically drop the 'vars' array which contains the values for the API and set the values directly on the parent array passed to the method. A bit of clarification in the documentation could certainly save folks some time. This got me both starting using the API as well as trying to convert from the API to internal for speed. Now the requests of add/edit work with loading the core files without api ? Quote
Jonathan Posted October 22, 2014 Author Report Posted October 22, 2014 Now the requests of add/edit work with loading the core files without api ? Well presumably it would work loading the core files - at this point I've got it dirtily converted into a plugin function I'm calling directly. I did that while ruling things out and there's no point in going back now. It's sped up this process I'm doing ten-fold. Don't have a full idea yet as I'm still converting things in my script from making API calls to now internal calls but I suspect it will take this, previously 2-3 hour long process down to 10-20 mins based on what I've tested thus far. Blesta Addons 1 Quote
Blesta Addons Posted October 22, 2014 Report Posted October 22, 2014 thanks for your exmplain . and more thanks if you can share later your experience with this custom solution , just to enrich the community ideas . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.