I have an app in which I have a few cron jobs (these are outside cake), what I would like to do is the save cache using (Cakephp Cache Helper) by triggering through cakephp shell and create pdfs after the cron completes.
The pdf creation and cache creation logic is in the cake controller.
What I am trying to do is to call the cakephp app from shell (from the cron outside cakephp) and call a function from the controller and write the cache and pdf creation logic in it.
How can we call Controllers in Cake Shell?
You can try using the requestAction method within your shell:
$this->requestAction(Router::url('controller'=>'MyController', 'action'=>'myAction'));
It isn't well documented that you can do this but you should ask yourself whether you should move the logic elsewhere outside of the controller (e.g. into a library).
Related
I have method in laravel controller with some logic that need to run in the background in an infinite loop. With core php with was simple as we used to set it nohup php and call the php file to run in the background. How could we do the same with laravel to run the things in background.
Note: I cannot use cronjob for this as its an infinite loop which need to kept running in the background
Kinda hard to imagine what task you want to accomplish, but you could create laravel command, which could call controller method directly.
How to call controller method from within command
Check comment under the answer to resolve controller correctly.
Next, you should run command by the supervisor.
Supervisor tutorial
you can use define cronjob on your linux machine or use laravel schedule library . look at the following link :
https://laravel.com/docs/5.1/scheduling
A while ago i was tasked to program a Typo3 extension to write so called .conf files for the icinga2 montoring tool (has nothing to do with Typo3). Still let me explain some parts of it: Basically the backend user needs to create records of records of specific classes and set values for each records properties. Then i need to process the records to create these .conf files with the specific values with a php script.
I was tasked to use the scheduler in Typo3 for this. And here come the problems: How do i use this? I checked the documentation (https://docs.typo3.org/typo3cms/extensions/scheduler/Introduction/Index.html), but i still can't wrap my head around how to use it for my task. I can easily write an Action in a controller of a class to be executed in the frontend and in turn generate the con files... basically manually without the scheduler. But where do i put my php code to be run by the scheduler? I somehow seem not to understand the basical principle of the scheduler. Can i just run an Action of a specific controller of a class of my extension like i would in the Frontend via the scheduler?
I would suggest you use a command controller for this task.
The documentation shows how to create a command controller, which also may accept arguments.
Command controller tasks can directly be executed by TYPO3 scheduler (see screenshot below)
You may even configure task arguments for command controller tasks in TYPO3 scheduler.
I recently installed laravel framework in my laptop.I installed laravel in my Xampp server's htdocs/laravel/laravel source path
How can I run execute written PHP codes normally in browsers and run execute them out side laravel framework?
That means if I create a new .php file in desktop that will show "hello world". Where I should keep that file or in which folder to show my this individual file run in browser only inside laravel framework.
You can put it inside your public directory. If your application has a domain of localhost you can access it via localhost/script.php. BUT this is extremely ill-advised as you are opening yourself to potential vulnerabilities depending on what your script does.
If it is for testing then fine. Otherwise you will have to put that somewhere in your application say app/scripts/script.php where it cannot be accessed via the browser (the only point of stand-alone scripts in web application is for CRON tasks or for CLI commands). If this is the case, you may want to take a look at http://laravel.com/docs/4.2/commands about writing your own artisan commands.
Simplest solution in make filename.blade.php file.
put it in resources/views/filename.blade.php and execute it using routes routes/web.php
Route::get("/filename", function(){
return view('filename');
});
I would recommend storing that code in a custom library inside of Laravel and including it within a controller.
You can put your PHP file inside your storage/app/public/filename.php folder in your laravel application folder and can run like
your_domain_name/storage/filename.php
I've created a deployment script for my Symfony applications that fetches updates from a git-repo. It downloads dependencies, updates schema, installs assets, then clears and warms up the cache
It works well (as far I know?) but I need a way to get/store the last time the cache was cleared. Preferably I don't want to write to a file or update a record in a database from the shell, I rather detect/fetch the the last time it was cleared and rebuilt inside my Symfony application.
Is there any way to do this? I thought of getting the created time of the prod cache folder..
Here's the script I wrote: https://github.com/StrikeForceZero/DeploySymfony/blob/master/DeploySymfony.sh
One way to do this would be to write to the Symfony logs using Symfony's built in logging service Monolog (http://symfony.com/doc/current/cookbook/logging/monolog.html). You can either create a Symfony console command (http://symfony.com/components/Console) that your script executes to write to the logs, or you can use inheritance to override one of the Symfony methods that you want to log, that simply calls the logger service, updates the log, and calls its parent method.
For example, instead of calling 'app/console cache:clear' you can call your child method that inherits from CacheClearCommand, update the configure method to set a new name for your command, override the execute method to call your log (either before or after the child executes its parent) and that should be about it. In your deployment script call your custom cache:clear command instead of Symfony's.
Is there a general place that I could put logic that can be shared between the controllers and commands in Laravel. I have functionality that will most often times be run from command line via stored procedure, but also need the same (or a subset) of the functionality via web.
Can I use controller logic within the command? Or call the command from the controller/route?
Or should I just build my own classes and include them as needed in both?
just create a app/libraries folder. In that create a custom_helpers.php file and autoload it. Store your methods that your going to be using often there. Think of it like the helper class provided by laravel by default.