Code Snippets

APCu with PHP 7 still exists and works | php

Remember, APCu is specific to ONE specific instance / server.

If you have multiple server environments, you will likely be better served by MEMCACHED or REDIS.

Although, in theory, you can indeed have multiple servers storing APC locally. But you may get front-end inconsistency!

E.g. One server collects APCu garbage and loses its cache and therefore gets fresh content, while another one still has it.

While I write this, I am thinking about an ugly hack to sync the APCu cache clean on a cron :)


function foo($lang, $testpalabra, $query)
// // let's make a key to store it in APCu.  It does not seem to accept associative arrays.
	$apcukey = $lang . "-" . $testpalabra;

	$apctest = apcu_fetch($apcukey);
	if ($apctest) {
// // great, we got a cache hit.  Let's return it and save our architecture some hard labour
		return $apctest;
	} else {
// // no cache found, time to do the heavy work like Mysql or jason file_put_contents

		$result = mysqli_query($con, $query); // // etc

// //	......	insert task here...

// // now we have the goods, let's store it in APCu so we don't need to fetch it again

// //......

		apcu_add($apcukey, $result); // // or whatever needs to be stored
		// // now pass it back - no one will know whether it came from APCu or not
		return $result;

Published: Mon 8th January 2018
||COMMENTS|| This site proudly uses PrismJS to display code snippets

If you like this page, please share it.

Code Links - PHP, JS, CSS, Bootstrap, Bash, Emmet, IntelliJ, Sublime etc.

My personal list of links which I keep here publicly incase they help someone else one day.

Code Snippets

Snippets of PHP code I have gathered over the years. I keep them here for my own repository but also to share with others. I always link back when I remember the source.

My Github Repos

A work in progress. I am going to make as many modules that I write in my devbox public as possible.

Kit's Homepage

This site was originally intended as a test bed for code. It now includes my blog about business and powerlifting, as well as games for Spanish language learning

© 2018