0

I use popen and ssh.

In one script, i need to restart the service spamassassin with :

$spamassassin = "service spamassassin restart &";
$spamassmilter = "service spamass-milter restart &";
shell_exec($spamassassin);
shell_exec($spamassmilter);

I want this process restart in the background, because my browser wait the service be restart to stop load the web page.

I try with :

$spamassassin = "service spamassassin restart &";

and

$spamassassin = "service spamassassin restart > exit.txt";

and

$spamassassin = "nohup service spamassassin restart";

But my browser wait the service is restart...

How can i restart the service, without my browser wait until all services are restarted ?

I use popen, ssh, exec

EDIT :

Finally I resolved my problem thanks to @immulatin for this link

Asynchronous shell exec in PHP

i use :

$spamassassin = "service spamassassin restart &> /dev/null &";
$spamassmilter = "service spamass-milter restart &> /dev/null &";

exec($spamassassin);
exec($spamassmilter);
Community
  • 1
  • 1
mpgn
  • 6,649
  • 8
  • 61
  • 97
  • service restart for SA needs to be done as root not your web user and you don't need the & or anything just "service spamassassin restart" – Dave Jun 24 '13 at 15:07
  • 1
    http://stackoverflow.com/questions/222414/asynchronous-shell-exec-in-php – immulatin Jun 24 '13 at 15:15

1 Answers1

0

Try using nohup.

http://en.wikipedia.org/wiki/Nohup

<?php
// Note the backticks!
`nohup service spamassassin restart &`
?>

Also, make sure the user running apache has enough permissions to restart this service.

Harold
  • 1,160
  • 1
  • 12
  • 23
  • doesn't work. The service can be restarted, but it takes too much time. – mpgn Jun 24 '13 at 15:17
  • restarting spam assassin does take a while its not an instant job if you want to run it in tandem then look at using a scheduler – Dave Jun 24 '13 at 15:19