PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 18, 2022

[FIXED] How to run a background process in symfony

 October 18, 2022     php, symfony     No comments   

Issue

I have a symfony commad that needes few minutes to be completed. And i want to run it by a http request. The problem is that the server kills the command process just after sending response, he has a timeout.

i tried to use symfony process asynchronously But still not working ( i get always the timeout problem).

I dont want use the kernel.terminate event, since it is not a best practice. Here is the code in my controller :

            $commandProcess=new Process('php  bin/console app:doSomeThing');
            $commandProcess->setWorkingDirectory('./../');
            $commandProcess->start();
            $commandProcess->setTimeout(50000000);

Any response will be much appreciated.


Solution

I had to desibale the process output and add '&' after the command Here the answer:

     new Process('php  bin/console app:dosomthing &');

    $commandProcess=new Process('php  bin/console app:dosomthing &');
    $commandProcess->setWorkingDirectory('./../');
    $commandProcess->disableOutput();
    $commandProcess->setTimeout(1800);
    $commandProcess->start();


Answered By - Cheikh HAIBALA
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing