Reputation: 73
First of all use windows.
I have the following code:
<?php
error_reporting(E_ALL);
$tiempo_inicio = microtime(true);
exec('C:\wamp\bin\php\php5.5.12\php.exe -e C:\wamp\www\mail.php > /dev/null &');
$tiempo_fin = microtime(true);
echo ($tiempo_fin - $tiempo_inicio);
?>
<?php
$tiempo_inicio = microtime(true);
$logs = fopen("test.txt","a+");
sleep(2);
$tiempo_fin = microtime(true);
fwrite($logs, ($tiempo_fin - $tiempo_inicio)."
");
sleep(4);
$tiempo_fin = microtime(true);
fwrite($logs, ($tiempo_fin - $tiempo_inicio)."
");
sleep(6);
$tiempo_fin = microtime(true);
fwrite($logs, ($tiempo_fin - $tiempo_inicio)."
");
echo 'fin';
?>
But it does not work I hope, because what I want is to run the file in the background without the user wait for the completion of this file.
What am I doing wrong?
Upvotes: 0
Views: 98
Reputation: 26
I've had success in the past on Windows using pclose
/popen
and the Windows start command instead of exec
. The downside to this is that it is difficult to react to any errors in the program you are calling.
I would try something like this (I'm not on a machine to test this today):
$command_string = 'C:\wamp\bin\php\php5.5.12\php.exe -f "C:\wamp\www\mail.php" -- variablestopass';
pclose(popen("start /B ".$command_string, 'r'));
Upvotes: 0
Reputation: 31654
You're talking about a non-blocking execution (where one process doesn't wait on another. PHP really can't do that very well (natively anyways) because it's designed around a single thread. Without knowing what your process does I can't comment on this precisely but I can make some suggestions
Upvotes: 1