Run php in the background

2

- I hope my explanation is clear - I have a PHP script that takes a long time to execute, so I decided to run it in the background, what happens is that even in the file that I run the second script, wait until finish this execution to answer. Is there any way to make this not happen?

File 1 in this run the 2 script.

$param1 = escapeshellcmd($idProduct);
        $param2 = escapeshellcmd($_POST["portales"]);
        $param3 = escapeshellcmd($_SESSION["username"]);
        exec("php -f C:\wamp64\www\ruta-del-fichero\test.php $param1 $param2 $param3 > salida.txt");

File 2 is the one that is executed from file 1.

<?php
include "CreateProductPortals.php";
require "conex.php";
$db = new SqlConexionCreations();
$portales = explode(",", $_SERVER['argv'][2]);
$usuario = $_SERVER['argv'][3];
$result = new CreateProductPortals($portales, $db, $_SERVER['argv'][1], $usuario);
$resultado = (is_array($result) || is_object($result)) ? json_encode($result):$result;
$query = "INSERT INTO [logs_creaciones] (usuario, resultado) VALUES ('{$usuario}', '{$resultado}')";
die(var_dump($db->query($query)));
    
asked by user22090 27.09.2018 в 00:47
source

1 answer

3

You need to start an asynchronous process with "popen ()" link

$command = 'ruta_del_script.php arg1 arg2... argn';
pclose(popen('start /b php.exe '.$command, 'r'));

[Important] php.ini must be: register_argc_argv = On and the directory of the php executable, "php.exe" must be in path of the environment variables.

    
answered by 27.09.2018 / 00:59
source