0

I'm trying to find an answer that doesn't seem to be covered on similar threads I've found here.

I have a page that takes a url from the user. I want to the execute five different scripts that will each access 3rd party sites to establish details on this URL, perform calculations and write the results to a database. Each script is a separate php file.

I've so far gathered that the way to do this would be through the exec command but I have two problems with this

1) I don't want the page's output (there isn't any - results go into the DB) 2) I want the scripts to run 'in the background' almost like a daemon or cron job, and for the page to load telling the user the details are retrieved and will be available shortly.

Does anyone have a code example of how I would launch the scripts, but not have to wait for them to finish executing before loading the page that the user sees?

thatguy
  • 797
  • 2
  • 9
  • 17
  • Check out this question: http://stackoverflow.com/questions/222414/asynchronous-shell-exec-in-php – Brian Fisher Feb 23 '11 at 20:22
  • I'm having problems relating the chosen answer to this situation and getting it to work. For example, how would I launch pagea.php , pageb.php and pagec.php that are located in the same folder? – thatguy Feb 23 '11 at 20:37

2 Answers2

1

Have you tried something like this?

exec('php -f script.php > /dev/null &');

The process will be ran in background and you don't have to wait for it to finish to execute another commands.

N Alex
  • 1,014
  • 2
  • 18
  • 29
0

You want something like gearman.

sdot257
  • 10,046
  • 26
  • 88
  • 122
  • Thanks. It looks ideal but my knowledge of PHP isnt that indepth. I was looking more for an example I could use from within my own app. – thatguy Feb 23 '11 at 20:32