Using streams in multi process environment

Today is the last instal­l­ment about PHP stre­ams. This time we will borrow some images from GitHub octo­dex using remote stre­ams and stream copy­ing. To add some spice, we’re going to use PHP in paral­lel proces­sing. If you thought PHP is single process srcrip­ting langu­age, I will ruin your world, sorry ;-)

Of course in real world projects there is always a trade off between time and reso­ur­ces. Forking process is CPU expen­sive work for server. We’re assu­ming we have plenty of CPU cycles and RAM, but short on time. Take a look on code below:

It took 5 secs to fetch 127 images. The same thing run in single fore­ach loop takes about 2 minutes…

Podobne wpisy:

  1. 2 ways to check stream mimetype
  2. SPL itera­tors with closure context switching
  3. (W miarę) bezpieczne urucha­mia­nie skryp­tów PHP poprzez shell_exec()
  4. Writing custom stream filters

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany.

Możesz użyć następujących tagów oraz atrybutów HTML-a: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <p> <pre lang="" line="" escaped=""> <q cite=""> <strike> <strong>