w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Sharing data between threads in PHP on Apache

Using Xcache, you can use the following API:

int   xcache_inc(string name [, int value [, int ttl]])

This will atomically increment the value identified by name and store it in shared memory that will live across requests. To retrieve the value from any of the running threads in Apache use:

mixed xcache_get(string name)

Note: When Apache (httpd) is restarted, these values are lost.

Note 2: By definition threads do share memory and easily share data given they are running within the same process. It is one of the primary reasons to use them when performance is critical and large amounts of data is processed in parallel and co-ordinated between threads rather than potentially slower IPC or complex shared-memory solutions. However, sharing data between threads is complicated, particularly when the data is mutable and should be undertaken by those with a thorough understanding of the challenges.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.