arrays - PHP - Multiple instances of script accessing same resources -


i have analyze lot of information. speed things i'll running multiple instances of same script @ same moment.

however there big chance scripts analyze same piece of information(duplicate) not slow down process.

if running 1 instance solve problem array(i save has been analyzed).

so have question how somehow sync array other "threads" ?

mysql option guess overkill? read memory sharing not sure if solution looking for.

so if has suggestions let me know.

regards

this trivial task using real multi-threading:

<?php /* want logs readable creating mutex output */ define ("log", mutex::create()); /* thread safe printf */ function slog($message, $format = null) {     $format = func_get_args();     if ($format) {         $message = array_shift($format);          if ($message) {             mutex::lock(log);             echo vsprintf(                 $message, $format);             mutex::unlock(log);         }     } }  /* pthreads descendant */ class s extends stackable {     public function run(){} }  /* thread manipulates shared data until it's gone */ class t extends thread {     public function __construct($shared) {         $this->shared = $shared;     }     public function run() {         /* use ::chunk if wanted bite off bit more work */         while (($next = $this->shared->shift())) {             slog(                 "%lu working item #%d\n", $this->getthreadid(), $next);         }     } }  $shared = new s(); /* fill dummy data */ while (@$o++ < 10000) {     $shared[]=$o; }  /* start threads */ $threads = array(); while (@$thread++ < 5) {     $threads[$thread] = new t($shared);     $threads[$thread]->start(); }  /* join threads */ foreach ($threads $thread)     $thread->join();  /* important; ::destroy ::create */ mutex::destroy(log); ?> 

the slog() function isn't required use case, thought useful show executable example readable output.

the main gist of multiple threads need reference common set of data manipulate data ...


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -