Reputation: 25691
I create a 1MB space of shread memory for my app.
Every user as ONE and only ONE array with some info, accesible from about 10 concurrent processes, and on its monitor, user can see the progress of every process.
Evey process clean it's owned values from client's array.
But .. in a growing situation ... 1 milion user with each one 1 empty array 'at every single moment in time' will give me this
shm_put_var(): not enough shared memory left
... How can i detect when size of shared area is 'low' ? So I can grow it
EDIT: i'm usuing shm_ functionts (for example shm_get_var())
In this set of function, nothing tell me that space is low before data in memory was corrupted ...
Upvotes: 2
Views: 1747
Reputation: 41
Perhaps you could estimate the size of the objects you cache and keep track of the remaining space yourself, by using utility functions like those:
public static function getSize($object){
return self::formatBytes(strlen(serialize($object)));
}
public static function formatBytes($bytes, $precision=2){
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision).' '.$units[$pow];
}
This might not be always 100% accurate, but should come close to the real object size.
Upvotes: 2
Reputation:
You can use the shell command, but this is dependent on what your hosting-service allows, if you so use that.
With shell_exec() you can call the a system function to read the task manager of your operating system.
For OSX for example you can use the "top" command line function to retrieve the free memory live. Easiest might be to just dump the whole activity-table and use regex to fetch the PHP process(es).
Upvotes: 1