Is it possible to execute command prompt from Laravel controller? If YES, then how can i execute a command and what is the best way to do this? If NO,is there any other way how i can do this?
I dont Know if I get it.
Cant you use
PHP system()?
If I'm wrong please explain clearly
http://php.net/manual/en/function.system.php
If you only need to run artisan commands (e.g. migrating the database) you can easily do that from your controller:
Route::get('/foo', function () {
$exitCode = Artisan::call('email:send', [
'user' => 1, '--queue' => 'default'
]);
//
});
Source: Laravel Docs
There are some packages available that give you a UI for calling Artisan commands, just search for "laravel artisan web".
If you need to execute other commands you should give us more information about what you're trying to do.
Not 100% sure what you mean with "command prompt" but you can execute commands directly from php with the exec function. This is often not a recommended approach though and I would suspect that it is possible that if you need to run exec there is a design issue in the application.
I would recommend that you consider other approaches to the problem and only use exec in very special conditions.
Related
guys.
I tried creating a migration, model and controller using the php artisan commands and it was all created, but with wrong permissions: if I want to modify something and then save it in these new files, I need to save using sudo, which is a waste of time. I'd like to know if there's a way to change those permissions when creating the files. The docker is already outside sudo.
Thanks a lot.
Run php artisan command with the user you will use to access this files later or change the permissions for the files after you create them.
I discovered for an incident that Laravel 6 schedule:run has a brother, called schedule:finish
But using artisan list it's not documented.
What does this console command do?
This hidden command added on Laravel 5.4 to handle the after callbacks of a given command.
Check Taylor Otwell's explanations on this PR:
This PR adds improvements to the scheduler. Previously, when
->runInBackground() was used "after" hooks were not run, meaning
output was not e-mailed to the developer (when using emailOutputTo.)
This change provides a new, hidden schedule:finish command that is
used to fire the after callbacks for a given command by its mutex
name. This command will not show in the Artisan console command list
since it uses the hidden command feature which is new in Symfony 3.2.
schedule:finish is used to setup actions for a process after its finishes execution,
if you have two or three level of processes that you want them to be executed one after another and depending on each other you use the schedule:finish command
I was wondering if this would be a way to go to create a command for a task, or at least if t would work?
Thanks in advance!
$schedule->command('someCommand')
->call('Path\To\MyController#method'{
})
->dailyAt('00:00');
Yes, there is a way to create your own custom commands. Read this tutorial to create your own artisan command:
https://laravel.com/docs/5.1/artisan
I have successfully integrated PHP RESQUE in my Ubuntu 14.
How can I get list of failed jobs in PHP to process them? I tried searching on web but could not find specific answer for PHP.
Please help. Thanks in advance.
You have two options: one is using the Resque-web UI: https://github.com/resque/resque-web if you want to install it from scratch or, better yet, there is a Docker container that makes it easy to get it up and running: https://hub.docker.com/r/ennexa/resque-web/~/dockerfile/
Resque-web has a tab to see the failed jobs and the option to reprocess them.
Programmatically, I don't think there is a built-in method that would allow that so I guess you would have to be creative here. For example, from resque-php Github page: You have the ability to retrieve a token identifying a job when you create it:
$token = Resque::enqueue('default', 'My_Job', $args, true);
With that information, you can then retrieve the job status:
$status = new Resque_Job_Status($token);
echo $status->get(); // Outputs the status
You will want to check for this:
Resque_Job_Status::STATUS_FAILED
This also might give you some ideas: https://github.com/chrisboulton/php-resque/issues/324
Is there a way in Laravel 4 to run my controller/action using PHP-CLI? I have a controller/action that I would like to extend to perform an alternative action if the request comes from the CLI, so is there a way to identify the request as a CLI request?
The Laravel documentation on this site seems to suggest that there is a method Request::cli() for determining if the current request is via the Artisan CLI but when I used the method in Laravel 4, it throws an error:
Call to undefined method Illuminate\Http\Request::cli()
Basically, I have just moved from CakePHP to Laravel and would like to accomplish something similar to as what's described in this article (for CakePHP) : Calling controller actions from cron and the command line
I understand that I can work with Laravel 4 Artisan Commands, but is the approach I would like to use possible? And if so, how?
As Rob already said, to determine if the current script is being run in the console use App::runningInConsole() or simple plain PHP php_sapi_name() == 'cli'.
As for running controller#action from console, you could use curl or wget to request one of your routes but I think the proper way of doing it would be to use a custom artisan command. Your controllers are classes so you can instantiate them and use as you please from within your artisan command:
$controller = new SomeController;
$controller->someAction();
Watch this video for an introduction to easily developing your own artisan commands.