开发者

how run other php code by one php code asynchronous?

开发者 https://www.devze.com 2023-03-12 15:46 出处:网络
explain by example : f.php : d$=$_Get[\'ad\']; print 开发者_JS百科d$; index.php : for $i=0 to 200000

explain by example : f.php :

d$=$_Get['ad'];
 print 开发者_JS百科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 ??


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


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号