Laravel call to controller method from command line to run in background - php

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

Related

Typo3 scheduler: Can i somehow execute Action of controllers of my extension with it? Or how to run my own code with it?

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.

How to call CLI from a controller on ZF2

Our system is written in ZF2. I'm trying to call a ZFTool console command programmatically, if there's a way to do that. All documentation I have found so far points to call a Controller action from CLI, instead of CLI programmatically from a controller.
If there's no default way to do this, a workaround would be fine as long as it's testable. Thanks in advance.
PS: I'm new to ZF2, I come from Laravel where you have a facade class to execute commands from a controller class Artisan::call('my:command').

calling route of Laravel project with Exec command

I've a project in Laravel 5, and I need to call a route of other project made in the same framework, I was thinkg in call this route using exec command of PHP, is possible to call a route?I've been callin PHP scripts and it works fine, but now I need to call a route an get the response. The reason of why I'm doing this of this way are a lot so I'll not explain it here or the post will get very long. Thank you!

Laravel : Command bus not going asynchronous

I'm using Laravel 5.1's Command bus to run a specific task (upload a file, validate then record it in my db) on a background process.
I tried uploading small csv file like 1.4kb (40 rows) and it worked.
When when i tried uploading a 1MB csv file (20000 rows), I noticed it is not running in background process. It waits for the job to be finished and then loads the correct page which is not the way I wanted it :(.
I think I followed the Laravel documentation on how to run a command bus in asynchronous process just by php artisan make:command PurchasePodcast --queued.
Reference
My code :
class ImportPricelistCommand extends Command implements SelfHandling, ShouldQueue
{
use InteractsWithQueue, SerializesModels;
Am i missing something? Please help.
In Laravel 5.1 the command bus is replace by jobs. You are using Laravel 5.1 and following 5.0 documentation.
The command bus was renamed jobs in Laravel 5.1, and the “command” stuff left to not break 5.0 applications. Jobs can be dispatched asynchronously as well as queued to be processed asynchronously.
Basically, you want to remove the ShouldQueue interface and InteractsWithQueue trait from your command/job class. As you may have gathered, this tells the dispatcher to queue them rather than process them synchronously.

CakePHP, Shell, PHP

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).

Categories