naser
naser

Reputation: 4437

how run other php code by one php code asynchronous?

explain by example : f.php :

d$=$_Get['ad'];
 print d$;

index.php :

 for $i=0 to 200000
     // run f.php?ad=i$

run f.php but dont wait to finish f.php how can do that?

  1. i find php asynchronus but i dont now this is working realy or existing other solution or is this best solution?!!

  2. when use exec and how ??

Upvotes: 0

Views: 2080

Answers (2)

Frankie
Frankie

Reputation: 25165

If you're running linux and have access to php CLI you can have something like this:

<?php
// this will launch worker to run something... 
shell_exec('php worker.php >/dev/null &');

// the rest of the flow goes here
...
?>

worker.php could be writting stuff to a database, sending emails, whatever...

Upvotes: 1

Geoffrey Wagner
Geoffrey Wagner

Reputation: 818

The term your looking for is called forking. Here is a link to all the PHP docs you will need to fork your code into async procs.

http://php.net/manual/en/function.pcntl-fork.php

Upvotes: 5

Related Questions