26global $shmkeys, $shmoffset;
52 'interventions' => 24,
71function dol_setcache($memoryid, $data, $expire = 0, $filecache = 0, $replace = 0)
77 if (strpos($memoryid,
'count_') === 0) {
83 if (
isModEnabled(
'memcached') && class_exists(
'Memcached')) {
86 if (empty($dolmemcache) || !is_object($dolmemcache)) {
87 $dolmemcache =
new Memcached();
89 $port = (empty($tmparray[1]) ? 0 : $tmparray[1]);
90 $result = $dolmemcache->addServer($tmparray[0], ($port || strpos($tmparray[0],
'/') !==
false) ? $port : 11211);
96 $memoryid = session_name().
'_'.$memoryid;
98 $dolmemcache->add($memoryid, $data, $expire);
99 $rescode = $dolmemcache->getResultCode();
101 return is_array($data) ? count($data) : (is_scalar($data) ? strlen($data) : 0);
102 } elseif (!empty($replace) && $rescode == Memcached::RES_NOTSTORED) {
103 $dolmemcache->replace($memoryid, $data, $expire);
104 $rescode = $dolmemcache->getResultCode();
106 return is_array($data) ? count($data) : (is_scalar($data) ? strlen($data) : 0);
113 } elseif (
isModEnabled(
'memcached') && class_exists(
'Memcache')) {
116 if (empty($dolmemcache) || !is_object($dolmemcache)) {
117 $dolmemcache =
new Memcache();
119 $port = (empty($tmparray[1]) ? 0 : $tmparray[1]);
120 $result = $dolmemcache->addServer($tmparray[0], ($port || strpos($tmparray[0],
'/') !==
false) ? $port : 11211);
126 $memoryid = session_name().
'_'.$memoryid;
128 $result = $dolmemcache->add($memoryid, $data, 0, $expire);
130 return is_array($data) ? count($data) : (is_scalar($data) ? strlen($data) : 0);
137 } elseif ($filecache > 0) {
138 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
139 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
140 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
142 $memoryid = session_name().
'_'.$memoryid;
143 $dircache =
'dolcache';
144 $pathcache = DOL_DATA_ROOT.
'/'.$dircache;
155 $cachedata = array(
"expire" => $expire,
"data" => $data);
156 $cachejson =
dolEncrypt(json_encode($cachedata));
157 if (!
dol_is_file($pathcache.
'/'.$memoryid.
'.cache') || $replace > 0) {
158 $result = file_put_contents($pathcache.
'/'.$memoryid.
'.cache', $cachejson);
159 dolChmod($pathcache.
'/'.$memoryid.
'.cache');
165 $conf->cache[
'cachememory_'.$memoryid] = $data;
166 $result = is_array($data) ? count($data) : (is_scalar($data) ? strlen($data) : 0);
184 if (strpos($memoryid,
'count_') === 0) {
191 if (
isModEnabled(
'memcached') && class_exists(
'Memcached')) {
193 if (empty($m) || !is_object($m)) {
194 $m =
new Memcached();
196 $port = (empty($tmparray[1]) ? 0 : $tmparray[1]);
197 $result = $m->addServer($tmparray[0], ($port || strpos($tmparray[0],
'/') !==
false) ? $port : 11211);
203 $memoryid = session_name().
'_'.$memoryid;
206 $data = $m->get($memoryid);
207 $rescode = $m->getResultCode();
212 } elseif ($rescode == 16) {
217 } elseif (
isModEnabled(
'memcached') && class_exists(
'Memcache')) {
219 if (empty($m) || !is_object($m)) {
222 $port = (empty($tmparray[1]) ? 0 : $tmparray[1]);
223 $result = $m->addServer($tmparray[0], ($port || strpos($tmparray[0],
'/') !==
false) ? $port : 11211);
229 $memoryid = session_name().
'_'.$memoryid;
231 $data = $m->get($memoryid);
243 } elseif ($filecache > 0) {
244 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
245 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
246 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
248 $memoryid = session_name().
'_'.$memoryid;
249 $dircache =
'dolcache';
250 $pathcache = DOL_DATA_ROOT.
'/'.$dircache;
251 if (!
dol_is_file($pathcache.
'/'.$memoryid.
'.cache')) {
254 $data = file_get_contents($pathcache.
'/'.$memoryid.
'.cache');
259 if ($json->expire > $now) {
270 if (isset(
$conf->cache[
'cachememory_'.$memoryid])) {
271 return $conf->cache[
'cachememory_'.$memoryid];
288 global $shmkeys, $shmoffset;
289 if (empty($shmkeys[$memoryid])) {
292 return (
int) ($shmkeys[$memoryid] + $shmoffset);
305 foreach ($shmkeys as $key => $val) {
307 if (!is_numeric($result) || $result > 0) {
308 $resarray[$key] = $result;
327 if (empty($shmkeys[$memoryid]) || !function_exists(
"shmop_write")) {
331 if (empty($shmkey)) {
335 $newdata = json_encode($data);
336 $size = strlen($newdata);
338 $handle = shmop_open($shmkey,
'c', 0644, 6 + $size);
340 $shm_bytes_written1 = shmop_write($handle, str_pad((
string) $size, 6), 0);
341 $shm_bytes_written2 = shmop_write($handle, $newdata, 6);
342 if ($shm_bytes_written1 + $shm_bytes_written2 != 6 +
dol_strlen($newdata)) {
343 print
"Couldn't write the entire length of data\n";
346 shmop_close($handle);
347 return ($shm_bytes_written1 + $shm_bytes_written2);
349 print
'Error in shmop_open for memoryid='.$memoryid.
' shmkey='.$shmkey.
' 6+size=6+'.$size;
366 if (empty($shmkeys[$memoryid]) || !function_exists(
"shmop_open")) {
370 if (empty($shmkey)) {
375 $handle = @shmop_open($shmkey,
'a', 0, 0);
377 $size = (int) trim(shmop_read($handle, 0, 6));
379 $data = json_decode(shmop_read($handle, 6, $size),
true);
384 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_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_setcache($memoryid, $data, $expire=0, $filecache=0, $replace=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.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.