0

I'm trying to make an ajax autocomplete search box that of course uses SQL, min 3 characters, and have a SQL view of relevant fields already set up and indexed in the db. The CPU still spikes when searching, which I expected as it's running a query for every character. I want to use Zend shm cache to speed up results and reduce CPU usage. The results are stored in an array which is to be cached like this:

while($row = db2_fetch_row($stmt)) {
  $fSearch[trim($row[0]).trim($row[1])] = array(/*array built here*/);
}
if (zend_shm_cache_store('fSearch', $fSearch, 10 * 60) === false) {
  error_log('Failed to store search cache!');
}

Of course there's actual data inside the array instead of comments, I just shortened the code for simplicity. Rows 0&1 form the PK, and this has tested to be working properly. It's the zend_shm_cache_store that fails because the error log gets flooded with 'Failed to store search cache!'. I read that zend_shm_cache_store can store any array that can be serialized - how can I tell if my data is serialized or can be serialized? Are there any other potential causes? I did make a test page that only stored a string and that was successful, so I know caching is on.

MaKR
  • 1,882
  • 2
  • 17
  • 29
  • Are you running Zend Server (CE) ? – markus Nov 26 '12 at 15:33
  • Why aren't you using the respective adapter? – markus Nov 26 '12 at 15:34
  • It is not community edition, framework v1.11.10, php v5.3.8. Respective adapter? – MaKR Nov 26 '12 at 16:00
  • Why are you calling `zend_shm_cache_store` like this? That's not the right way to do it, read the manual of Zend_Cache : http://framework.zend.com/manual/1.12/en/zend.cache.html – markus Nov 26 '12 at 16:09
  • I've used zend_shm_cache_store like this on other pages successfully, got the howto here: http://files.zend.com/help/Zend-Platform/zend_cache_api.htm – MaKR Nov 26 '12 at 16:27
  • In that case you should remove the zend-framework tag since this has nothing to do with zend-framework. – markus Nov 26 '12 at 16:36
  • How does zend_shm_cache_store/fetch not relate to Zend Framework? – MaKR Nov 26 '12 at 16:42
  • It has nothing to do with Zend Framework, it's a completely unrelated API belonging to the Zend Server infrastructure. – markus Nov 26 '12 at 16:42
  • What does $fSearch contain? Did you dump it? – markus Nov 26 '12 at 16:43
  • Yes, I used output buffer to fwrite and it was ~7.7MB, it contains 4 fields of varchars, 1 is 4 char or less, 2nd is 12 char or less, 3rd is 25 char or less, and last is 100 char or less. I'm using mb_convert_encoding(trim($row[x]), "UTF-8") for each index in the array. The varchars do contain special characters, so I wonder if that's possibly why the store is failing since data has to be serialized. I don't know what's allowed and what's not in a string that is to be serialized so that's the 1st thing I'd like to verify once I know how. – MaKR Nov 26 '12 at 16:51

1 Answers1

0

Solved: cache size was too small for array - increased cache size and it worked fine. Sorry for the trouble.

MaKR
  • 1,882
  • 2
  • 17
  • 29