Create PHP background process

0

I am setting up a Web application with Codeigniter in which a section must execute a process that takes a long time to finish, approximately 40 min.

The process works fine, when executing it outside the application. However, when it was executed inside, the application waits for the process to finish, and it does not allow me to interact with the rest of the options. (Even if you close the window and open a new one with the application)

The process executed it like this:

  • I make the call to the function via angular http.

    $ scope.ejecutarProceso = function () {      $ http.post ('products / countingproducts'); }

  • Class products

    Public function conteoProductos(){
      //Está función sólo busca en la base de datos los productos, genera conteos por cada característica y los inserta en una nueva tabla
      $this->producto->insertar conteo();
    }
    

    I've also tried to run it out of the framework as

    passthru('usr/bin/php '.$_SERVER['DOCUMENT_ROOT']."/app/procesos/conteo.php");
    
        
    asked by jmrtn 12.10.2017 в 16:48
    source

    1 answer

    1

    Add the & symbol to the command line to tell the operating system to run it in the background. If you obviously do not want to know anything about the result, redirect everything to null.

    In your case the command would be such that:

    passthru('usr/bin/php '.$_SERVER['DOCUMENT_ROOT']."/app/procesos/conteo.php >/dev/null 2>/dev/null &");
    
      

    NOTE: This only works for operating systems * nix

        
    answered by 12.10.2017 / 17:59
    source