26global $shmkeys, $shmoffset;
52 'interventions' => 24,
70function dol_setcache($memoryid, $data, $expire = 0, $filecache = 0)
76 if (strpos($memoryid,
'count_') === 0) {
82 if (isModEnabled(
'memcached') && class_exists(
'Memcached')) {
85 if (empty($dolmemcache) || !is_object($dolmemcache)) {
86 $dolmemcache =
new Memcached();
88 $port = (empty($tmparray[1]) ? 0 : $tmparray[1]);
89 $result = $dolmemcache->addServer($tmparray[0], ($port || strpos($tmparray[0],
'/') !==
false) ? $port : 11211);
95 $memoryid = session_name().
'_'.$memoryid;
97 $dolmemcache->add($memoryid, $data, $expire);
98 $rescode = $dolmemcache->getResultCode();
100 return is_array($data) ? count($data) : (is_scalar($data) ? strlen($data) : 0);
104 } elseif (isModEnabled(
'memcached') && class_exists(
'Memcache')) {
107 if (empty($dolmemcache) || !is_object($dolmemcache)) {
108 $dolmemcache =
new Memcache();
110 $port = (empty($tmparray[1]) ? 0 : $tmparray[1]);
111 $result = $dolmemcache->addServer($tmparray[0], ($port || strpos($tmparray[0],
'/') !==
false) ? $port : 11211);
117 $memoryid = session_name().
'_'.$memoryid;
119 $result = $dolmemcache->add($memoryid, $data, 0, $expire);
121 return is_array($data) ? count($data) : (is_scalar($data) ? strlen($data) : 0);
128 } elseif ($filecache > 0) {
129 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
130 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
131 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
133 $memoryid = session_name().
'_'.$memoryid;
134 $dircache =
'dolcache';
135 $pathcache = DOL_DATA_ROOT.
'/'.$dircache;
146 $cachedata = array(
"expire" => $expire,
"data" => $data);
147 $cachejson =
dolEncrypt(json_encode($cachedata));
148 if (!
dol_is_file($pathcache.
'/'.$memoryid.
'.cache')) {
149 $result = file_put_contents($pathcache.
'/'.$memoryid.
'.cache', $cachejson);
155 $conf->cache[
'cachememory_'.$memoryid] = $data;
156 $result = is_array($data) ? count($data) : (is_scalar($data) ? strlen($data) : 0);
174 if (strpos($memoryid,
'count_') === 0) {
181 if (isModEnabled(
'memcached') && class_exists(
'Memcached')) {
183 if (empty($m) || !is_object($m)) {
184 $m =
new Memcached();
186 $port = (empty($tmparray[1]) ? 0 : $tmparray[1]);
187 $result = $m->addServer($tmparray[0], ($port || strpos($tmparray[0],
'/') !==
false) ? $port : 11211);
193 $memoryid = session_name().
'_'.$memoryid;
196 $data = $m->get($memoryid);
197 $rescode = $m->getResultCode();
202 } elseif ($rescode == 16) {
207 } elseif (isModEnabled(
'memcached') && class_exists(
'Memcache')) {
209 if (empty($m) || !is_object($m)) {
212 $port = (empty($tmparray[1]) ? 0 : $tmparray[1]);
213 $result = $m->addServer($tmparray[0], ($port || strpos($tmparray[0],
'/') !==
false) ? $port : 11211);
219 $memoryid = session_name().
'_'.$memoryid;
221 $data = $m->get($memoryid);
233 } elseif ($filecache > 0) {
234 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
235 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
236 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
238 $memoryid = session_name().
'_'.$memoryid;
239 $dircache =
'dolcache';
240 $pathcache = DOL_DATA_ROOT.
'/'.$dircache;
241 if (!
dol_is_file($pathcache.
'/'.$memoryid.
'.cache')) {
244 $data = file_get_contents($pathcache.
'/'.$memoryid.
'.cache');
249 if ($json->expire > $now) {
260 if (isset(
$conf->cache[
'cachememory_'.$memoryid])) {
261 return $conf->cache[
'cachememory_'.$memoryid];
278 global $shmkeys, $shmoffset;
279 if (empty($shmkeys[$memoryid])) {
282 return $shmkeys[$memoryid] + $shmoffset;
295 foreach ($shmkeys as $key => $val) {
297 if (!is_numeric($result) || $result > 0) {
298 $resarray[$key] = $result;
317 if (empty($shmkeys[$memoryid]) || !function_exists(
"shmop_write")) {
321 if (empty($shmkey)) {
325 $newdata = serialize($data);
326 $size = strlen($newdata);
328 $handle = shmop_open($shmkey,
'c', 0644, 6 + $size);
330 $shm_bytes_written1 = shmop_write($handle, str_pad((
string) $size, 6), 0);
331 $shm_bytes_written2 = shmop_write($handle, $newdata, 6);
332 if ($shm_bytes_written1 + $shm_bytes_written2 != 6 +
dol_strlen($newdata)) {
333 print
"Couldn't write the entire length of data\n";
336 shmop_close($handle);
337 return ($shm_bytes_written1 + $shm_bytes_written2);
339 print
'Error in shmop_open for memoryid='.$memoryid.
' shmkey='.$shmkey.
' 6+size=6+'.$size;
356 if (empty($shmkeys[$memoryid]) || !function_exists(
"shmop_open")) {
360 if (empty($shmkey)) {
365 $handle = @shmop_open($shmkey,
'a', 0, 0);
367 $size = (int) trim(shmop_read($handle, 0, 6));
369 $data = unserialize(shmop_read($handle, 6, $size));
374 shmop_close($handle);
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
dol_setcache($memoryid, $data, $expire=0, $filecache=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid, $filecache=0)
Read a memory area shared by all users, all sessions on server.
dol_listshmop()
Return list of contents of all memory area shared.
dol_setshmop($memoryid, $data, $expire)
Save data into a memory area shared by all users, all sessions on server.
dol_getshmopaddress($memoryid)
Return shared memory address used to store dataset with key memoryid.
dol_getshmop($memoryid)
Read a memory area shared by all users, all sessions on server.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='')
Encode a string with a symmetric encryption.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.