News for hackers. Stuff that matters.
Re:PHP Dark Arts: Shared Memory Segments (IPC) by duskwuff on Tuesday September 28, 2010 @11:29PM (#1738239)
PHP: Bringing you yesterday's IPC today!

  *: SysV shared memory is incredibly clumsy to implement anything more complex than a cache in, and memcached still does a better job of that. There's really very few reasons you would ever want to use it in production code.
Re:PHP Dark Arts: Shared Memory Segments (IPC) by vital101 on Wednesday September 29, 2010 @07:27AM (#1738969)
In fairness, PHP provides other methods of IPC as well. http://www.php.net/manual/en/book.sem.php
Re:PHP Dark Arts: Shared Memory Segments (IPC) by duskwuff on Wednesday September 29, 2010 @11:13AM (#1739680)
Those are all still cruddy SysV IPC methods you're pointing to. They're marginally better than just throwing data into shared memory and hoping it sticks, but you're still much better off sending messages across a UNIX domain socket.
Re:PHP Dark Arts: Shared Memory Segments (IPC) by lukefabish on Tuesday September 28, 2010 @09:06PM (#1737949)
Kinda cool, but can anyone imagine why'd you'd do this with PHP?
Re:PHP Dark Arts: Shared Memory Segments (IPC) by dhotson on Tuesday September 28, 2010 @10:00PM (#1738065)
I had a go at using this a little while ago to implement (erlang style) message passing concurrency in PHP:

http://github.com/dhotson/phork

The main use case is something like: Let's say you've got a mysql query that's going to take a few seconds. In the meantime, you can do some other useful work in PHP while the query runs.

Re:PHP Dark Arts: Shared Memory Segments (IPC) by atomical on Tuesday September 28, 2010 @11:00PM (#1738190)
The amount of complexity it could introduce to an application doesn't seem worth the minimal amount of gain.
Re:PHP Dark Arts: Shared Memory Segments (IPC) by dhotson on Wednesday September 29, 2010 @12:16AM (#1738302)
Probably true. But it depends. Let's say you've got 5 queries that take 1 second each.. There's a potential 5x speedup if you can run them in parallel.

I think some basic concurrency support in PHP (such as Futures) would have a pretty huge benefit. The other alternative is to have async APIs for libraries like mysql.

You could argue that anything that is taking too long that it needs parellelizing is probably a candidate for a background queue + frontend polling (or similar).

Re:PHP Dark Arts: Shared Memory Segments (IPC) by atomical on Wednesday September 29, 2010 @12:55AM (#1738365)
It still doesn't make sense to me. I can either use my time to fix the queries or use my time to play around with this disaster waiting to happen.
Re:PHP Dark Arts: Shared Memory Segments (IPC) by dhotson on Wednesday September 29, 2010 @01:24AM (#1738404)
It's not just db queries though.. it's also things like 3rd party API calls (S3 for example).

Basically anything where you're blocked waiting for a response you could be busy doing something else.

Synchronous APIs are kind of wasteful in a lot of cases. Node.js does a good job of this by using async APIs.

It's a tradeoff. But the extra complexity can be worth it if it means your pages load 2x faster.

Re:PHP Dark Arts: Shared Memory Segments (IPC) by mthoms on Tuesday September 28, 2010 @11:40PM (#1738258)
My web app has a large amount of data that needs random portions to be served by a PHP script. Because speed is of utmost importance, the data resides in RAM.

I first built a working solution in PHP using IPC Shared Memory Segments and later ditched it in favour of PHP+Redis (you could use your own NoSQL datastore of choice of course).

For me, it was way simpler/cleaner to implement and I got a bunch of features for free.

Re:PHP Dark Arts: Shared Memory Segments (IPC) by rendezvouscp on Wednesday September 29, 2010 @12:56AM (#1738366)
Shared memory can be handy when you need to keep a secret off disk yet accessible while a machine is running.