Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

389
Visualizações
Execute a node script in Laravel

I need to run a node script inside my Laravel application.

I've tried using the Symfony Process, but it kill the process after the PHP execution and I need to keep the node process running, so my next step was try to use the shell_exec and exec functions. It's worked nice in the tinker and in Tinkerwell, but when I try to use inside the Laravel class it gives the following error 500:

production.ERROR: Call to undefined function shell_exec() {"exception":"[object] (Error(code: 0): Call to undefined function shell_exec() at ...

As it is a VPS I set my php.ini to disable_functions= but it still not working inside Laravel, only if I use it outside the framework.

Thanks in advance and sorry for my bad English.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Unfortunately this can't be done with exec() (nor system() or shell_exec()).

But if you install the pcntl extension, define something like:

<?php

function detached_exec($cmd) {
    $pid = pcntl_fork();
    if ($pid == 0) {
        // Childe process main-loop goes here.
        posix_setsid();
        exec($cmd);
        exit(0);
    } else if ($pid == -1) {
        // Process fork failed.
        return FALSE;
    }
    return $pid;
}

And use like:

// Edit this:
$cmd = 'node --version';

$pid = detached_exec($cmd);
if($pid === FALSE) {
    echo 'exec failed';
}
over 4 years ago · Santiago Trujillo Relatório

0

I ended giving up. I've developed an workaround.

Instead calling the node file by PHP, I made a node script whit express who receives a POST request and start the code.

Now I can put my node code in another server and it will keep running with no problems and make my system scalable.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda