Ben sınıf dosya yolları sınıf adları bir harita depolamak için APC kullanıyorum. Benim özdevinimli_yükle işlevi böyle harita oluşturmak:
$class_paths = apc_fetch('class_paths');
// If the class path is stored in application cache - search finished.
if (isset($class_paths[$class])) {
return require_once $class_paths[$class];
// Otherwise search in known places
} else {
// List of places to look for class
$paths = array(
'/src/',
'/modules/',
'/libs/',
);
// Search directories and store path in cache if found.
foreach ($paths as $path) {
$file = DOC_ROOT . $path . $class . '.php';
if (file_exists($file)) {
echo 'File was found in => ' . $file . '<br />';
$class_paths[$class] = $file;
apc_store('class_paths', $class_paths);
return require_once $file;
}
}
}
Ben daha fazla sınıfları yüklenir gibi, onlar haritasına eklenir görebilirsiniz, ama bir noktada apc_fetch
, bir sayfa talep ortasında döner NULL
, yerine dönen haritası.
Getting => class_paths
Array
(
[MCS\CMS\Helper\LayoutHelper] => /Users/mbl/Documents/Projects/mcs_ibob/core/trunk/src/MCS/CMS/Helper/LayoutHelper.php
[MCS\CMS\Model\Spot] => /Users/mbl/Documents/Projects/mcs_ibob/core/trunk/src/MCS/CMS/Model/Spot.php
)
Getting => class_paths
{null}
Birçok kez önbelleğe alınan değer de sayfa istekleri arasında gitmiş olacak.
Bu ne için nedeni ne olabilir?
PHP 5.3 çalıştıran bir uzantısı (PECL) olarak APC kullanıyorum.
UPDATE: In the comments below you will see people stating that APC is not persistent and that it is not to be trusted. But in my case the code is executed in one page request between 15-50ms. Shouldn't I be able to trust the APC for that long?
UPDATE:
It seems that the cache contains multiple entries with the same key, when it should only contain one - that is overwritten the value when invoking apc_store()
. I hope this can help someone understand the problem. (I've disabled slam defense and write lock)
Array
(
[num_slots] => 4099
[ttl] => 0
[num_hits] => 0
[num_misses] => 3
[num_inserts] => 9678
[expunges] => 0
[start_time] => 1293109072
[mem_size] => 40064
[num_entries] => 8
[file_upload_progress] => 1
[memory_type] => mmap
[locking_type] => file
[cache_list] => Array
(
[0] => Array
(
[info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::column_info
[ttl] => 0
[type] => user
[num_hits] => 0
[mtime] => 1293109072
[creation_time] => 1293109072
[deletion_time] => 0
[access_time] => 1293109072
[ref_count] => 0
[mem_size] => 12456
)
[1] => Array
(
[info] => mcs:odk:class_paths
[ttl] => 3600
[type] => user
[num_hits] => 0
[mtime] => 1293109072
[creation_time] => 1293109072
[deletion_time] => 0
[access_time] => 1293109072
[ref_count] => 0
[mem_size] => 648
)
[2] => Array
(
[info] => mcs:odk:class_paths
[ttl] => 3600
[type] => user
[num_hits] => 0
[mtime] => 1293109072
[creation_time] => 1293109072
[deletion_time] => 0
[access_time] => 1293109072
[ref_count] => 0
[mem_size] => 648
)
[3] => Array
(
[info] => mcs:odk:class_paths
[ttl] => 3600
[type] => user
[num_hits] => 0
[mtime] => 1293109072
[creation_time] => 1293109072
[deletion_time] => 0
[access_time] => 1293109072
[ref_count] => 0
[mem_size] => 648
)
[4] => Array
(
[info] => mcs:odk:class_paths
[ttl] => 3600
[type] => user
[num_hits] => 0
[mtime] => 1293109072
[creation_time] => 1293109072
[deletion_time] => 0
[access_time] => 1293109072
[ref_count] => 0
[mem_size] => 648
)
[5] => Array
(
[info] => mcs:odk:class_paths
[ttl] => 3600
[type] => user
[num_hits] => 0
[mtime] => 1293109072
[creation_time] => 1293109072
[deletion_time] => 0
[access_time] => 1293109072
[ref_count] => 0
[mem_size] => 648
)
[6] => Array
(
[info] => mcs:odk:class_paths
[ttl] => 3600
[type] => user
[num_hits] => 0
[mtime] => 1293109072
[creation_time] => 1293109072
[deletion_time] => 0
[access_time] => 1293109072
[ref_count] => 0
[mem_size] => 648
)
[7] => Array
(
[info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::merged_column_info
[ttl] => 0
[type] => user
[num_hits] => 0
[mtime] => 1293109072
[creation_time] => 1293109072
[deletion_time] => 0
[access_time] => 1293109072
[ref_count] => 0
[mem_size] => 23720
)
)
[deleted_list] => Array
(
)
)