Jump to content


gizmola

Member Since 06 May 2003
Offline Last Active Today, 05:09 AM

Posts I've Made

In Topic: How can I cache more than just simple variables in the environment?

18 August 2014 - 04:32 PM

Quick update -- recently I became aware that with php5.5 the opcode cache feature of APC is no longer relevant as the zend opcode cache made it into the 5.5 base.

 

If you still want to use the cache feature of APC you need to instead install APCU.  I haven't played with this yet, but I assume it's simple enough that api and features are probably still relevant to what I've already discussed in the previous post.


In Topic: sessions destroy

18 August 2014 - 04:22 PM

Your "namespacing" isn't anything more than setting up an array key under session.  The code in question seems to be concerned with insuring that the actual session file is removed from the server.  You aren't ever going to be able to do that with your "session namespace" because it depends on the continued existence of the session file.

 

So -- to Jacques1 point, you should omit all the code that is attempting to mess around with the session lifetime settings (a really bad idea that would actually cause all the server session files to be removed) and just go with simple code that unsets the existing keys.


In Topic: How can I cache more than just simple variables in the environment?

17 August 2014 - 05:23 PM

I'll dog pile and 2nd Kicken's answer.

 

When you look into "caching" what that really means is "memory caching".  Memory caching is of course many times faster than either disk or db access in most cases.  I want to point out that by default php sessions are stored in small files on the server.  File IO is often pretty fast, especially with a system that has plenty of memory given over to disk buffering, but it's often not as fast nor as reliable as memory.  And as you already opined, if these are truly shared variables its wasteful to be replicating that data in sessions anyways.

 

Of the memory caching options, there are 2 basic varieties -- "per server" and "shared".  If you have a single server, you can setup any of the shared options and run them on the same server, and you essentially have a "per server" setup, but typically the "shared" caches are used in server clusters where one or more "server" caches service 1-n front end servers (Webserver +php) behind a load balancer.

 

The per-server cache that many people already have available is APC.  Primarily it's used for opcode caching, but it also can be used explicitly as a data cache.  Under *nix servers, APC grabs "shared memory" from the OS, so it's basically dedicated memory that is reserved for use by the system.  As it is essentially bound to php (which is often bound to the web server, as in a mod_apache setup) its not sharable across servers.  That might be fine, and you can kill 2 birds with one stone by reading all your configuration data and strings through the cache.  Once the cache is warmed, this data should come right out of memory as you would like it to.  Depending on the size of your code base, you might need to tweak the settings to insure you have enough available memory to keep your dataset in memory.  

 

Otherwise, one of the benefits is it's lack of complexity and extreme access speed -- no networking involved or getting in the way.

 

Alternatively, the most used server process caches are Memcache and Redis.  Memcache of course was made famous by Facebook who utilized it heavily in their early days.  Memcache is basically as simple as APC in most ways, but was designed for large datasets (often used to front relational database result sets).    While simple, it has significant gotchas you have to understand, but has many large installations.   More overhead than APC, but for name/value caching, it's been the goto product for a lot of the internet's most famous high traffic sites.

 

Redis can be used like Memcache, as a simple "key" (name/value) store, but it has a lot of other features that appeal to certain people.  First and foremost, it can be storage backed -- where you can utilize its ability 

 

Redis is similar and can be used for simple name/value storage, but it has some tricks that the other caches don't.  It has several options for persisting data, which can alleviate the need for "cache warming" on system startup, and programmatically gives you all sorts of features that might be useful for queueing, like pub/sub, "lists" which unlike memcache or APC can be manipulated (the value is not just a black box, but structured data you can sort, push pop and search)  amongst other uses.

 

As the saying goes, Redis is very fast as an in-memory cache, but it's not as fast as memcache or APC, and it's more complex and requires a larger footprint.

 

Hope this helps elaborate on the major players I've used in the php application space, and gives you a leg up on your research.  From the sound of it, any of the 3 will work for you, so it's just a matter of considering your use case, and doing some testing.


In Topic: Got great help here, but having trouble implementing?

17 August 2014 - 04:57 PM

I just flat out love you guys.  :-*

 

 

 

I just cannot thank you enough.  This is the kindest forum, to date, I've sought any kind of help from. 

 

Glad you got things working, and the words of thanks for the members who tirelessly help people out, are much appreciated, and rarely acknowledged.


In Topic: sessions destroy

16 August 2014 - 02:19 PM

Your code has some sort of namespacing feature I don't understand. Any efforts you make to remove the session data is going to break that, so I don't really get what that is about. In general, however, php gives you a way of removing session data, and invalidating an id cookie. It is this:


// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
session_destroy();

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com