Webservice error on Laravel 5.7

Asked

Viewed 276 times

3

I’m trying to create a WebService for Laravel using the symfony/process, if I run it in windows command it fills the log successfully (php artisan gerar:arquivo 12 param1 1000), but when I try to run my route it does not fill the log, it returns me the following error:

Symfony\Component\Process\Exception\ProcessFailedException: The command "php artisan gerar:arquivo 12 param1 1000" failed.

Exit Code: ()

Working directory: C:\xampp\htdocs\pw

Output:
================


Error Output:
================
 in file C:\xampp\htdocs\pw\app\Http\Controllers\PwController.php on line 339
Stack trace:
  1. Symfony\Component\Process\Exception\ProcessFailedException->() C:\xampp\htdocs\pw\app\Http\Controllers\PwController.php:339
  2. App\Http\Controllers\PwController->pw() C:\xampp\htdocs\pw\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54
  3. call_user_func_array() C:\xampp\htdocs\pw\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54
  4. Illuminate\Routing\Controller->callAction() C:\xampp\htdocs\pw\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php:45
  5. Illuminate\Routing\ControllerDispatcher->dispatch() C:\xampp\htdocs\pw\vendor\laravel\framework\src\Illuminate\Routing\Route.php:212

Follows my code:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class Gerar extends Command
{

    protected $signature = 'gerar:arquivo {id} {param} {page_size}';
    protected $description = 'Aplicação para Gerar PDF';


    public function handle()
    {
        $page_size = $this->argument('page_size');
        $id = $this->argument('id');
        $param = $this->argument('param');

        Log::info($page_size);
        Log::info($id);
        Log::info($filtro);

    }

}

Note that I am generating one Log with data to test but not enough to fill the log, it seems that it stops in the controller.

And the controller:

public function gerar(Request $request)
{
        $process = new Process(sprintf("php artisan gerar:arquivo %d %s %d", 1299, "param1", 1000), base_path());
        $process->start();
        //$process->wait();
}

Also note that if I break down the line //$process->wait(); it works, but I have to wait for the end of the processing WebService and I don’t want that.

  • 1

    The $process->Wait() loops?

  • 1

    Take a look at these articles https://laracasts.com/discuss/channels/general-discussion/running-artisan-command-through-symfony-process https://stackoverflow.com/questions/27022516/controlling-an-interactive-process-with-php-using-symfony-process

1 answer

1

According to the documentation, here you are the correct way to call a command in a route/controller, e.g.:

$exitCode = Artisan::call('email:send', [
    'user' => 1, '--queue' => 'default'
]);
  • He doesn’t want it, he wants to generate logs with Windows

Browser other questions tagged

You are not signed in. Login or sign up in order to post.