| 1 |
/* |
|---|
| 2 |
+----------------------------------------------------------------------+ |
|---|
| 3 |
| eAccelerator project | |
|---|
| 4 |
+----------------------------------------------------------------------+ |
|---|
| 5 |
| Copyright (c) 2004 - 2005 eAccelerator | |
|---|
| 6 |
| http://eaccelerator.net | |
|---|
| 7 |
+----------------------------------------------------------------------+ |
|---|
| 8 |
| This program is free software; you can redistribute it and/or | |
|---|
| 9 |
| modify it under the terms of the GNU General Public License | |
|---|
| 10 |
| as published by the Free Software Foundation; either version 2 | |
|---|
| 11 |
| of the License, or (at your option) any later version. | |
|---|
| 12 |
| | |
|---|
| 13 |
| This program is distributed in the hope that it will be useful, | |
|---|
| 14 |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 15 |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|---|
| 16 |
| GNU General Public License for more details. | |
|---|
| 17 |
| | |
|---|
| 18 |
| You should have received a copy of the GNU General Public License | |
|---|
| 19 |
| along with this program; if not, write to the Free Software | |
|---|
| 20 |
| Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
|---|
| 21 |
| MA 02111-1307, USA. | |
|---|
| 22 |
| | |
|---|
| 23 |
| A copy is availble at http://www.gnu.org/copyleft/gpl.txt | |
|---|
| 24 |
+----------------------------------------------------------------------+ |
|---|
| 25 |
| Author(s): Dmitry Stogov <dstogov@users.sourceforge.net> | |
|---|
| 26 |
+----------------------------------------------------------------------+ |
|---|
| 27 |
$Id$ |
|---|
| 28 |
*/ |
|---|
| 29 |
|
|---|
| 30 |
#include "eaccelerator.h" |
|---|
| 31 |
#include "eaccelerator_version.h" |
|---|
| 32 |
|
|---|
| 33 |
#ifdef HAVE_EACCELERATOR |
|---|
| 34 |
#ifdef WITH_EACCELERATOR_SHM |
|---|
| 35 |
|
|---|
| 36 |
#include "cache.h" |
|---|
| 37 |
#include "shm.h" |
|---|
| 38 |
|
|---|
| 39 |
#include "zend.h" |
|---|
| 40 |
#include "zend_API.h" |
|---|
| 41 |
#include "zend_extensions.h" |
|---|
| 42 |
|
|---|
| 43 |
/* where to cache the keys */ |
|---|
| 44 |
eaccelerator_cache_place eaccelerator_keys_cache_place = |
|---|
| 45 |
eaccelerator_shm_and_disk; |
|---|
| 46 |
|
|---|
| 47 |
/* set the eaccelerator_keys_cache_place */ |
|---|
| 48 |
PHP_INI_MH (eaccelerator_OnUpdateKeysCachePlace) |
|---|
| 49 |
{ |
|---|
| 50 |
if (strncasecmp ("shm_and_disk", new_value, sizeof ("shm_and_disk")) == 0) |
|---|
| 51 |
eaccelerator_keys_cache_place = eaccelerator_shm_and_disk; |
|---|
| 52 |
|
|---|
| 53 |
else if (strncasecmp ("shm", new_value, sizeof ("shm")) == 0) |
|---|
| 54 |
eaccelerator_keys_cache_place = eaccelerator_shm; |
|---|
| 55 |
|
|---|
| 56 |
else if (strncasecmp ("shm_only", new_value, sizeof ("shm_only")) == 0) |
|---|
| 57 |
eaccelerator_keys_cache_place = eaccelerator_shm_only; |
|---|
| 58 |
|
|---|
| 59 |
else if (strncasecmp ("disk_only", new_value, sizeof ("disk_only")) == 0) |
|---|
| 60 |
eaccelerator_keys_cache_place = eaccelerator_disk_only; |
|---|
| 61 |
|
|---|
| 62 |
else if (strncasecmp ("none", new_value, sizeof ("none")) == 0) |
|---|
| 63 |
eaccelerator_keys_cache_place = eaccelerator_none; |
|---|
| 64 |
|
|---|
| 65 |
return SUCCESS; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
/******************************************************************************/ |
|---|
| 69 |
/* PHP function entries */ |
|---|
| 70 |
/******************************************************************************/ |
|---|
| 71 |
|
|---|
| 72 |
PHP_FUNCTION (eaccelerator_lock) |
|---|
| 73 |
{ |
|---|
| 74 |
char *key; |
|---|
| 75 |
int key_len; |
|---|
| 76 |
|
|---|
| 77 |
if (zend_parse_parameters (ZEND_NUM_ARGS ()TSRMLS_CC, "s", &key, &key_len) |
|---|
| 78 |
== FAILURE) |
|---|
| 79 |
return; |
|---|
| 80 |
|
|---|
| 81 |
if (eaccelerator_lock (key, key_len TSRMLS_CC)) { |
|---|
| 82 |
RETURN_TRUE; |
|---|
| 83 |
} else { |
|---|
| 84 |
RETURN_FALSE; |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
PHP_FUNCTION (eaccelerator_unlock) |
|---|
| 89 |
{ |
|---|
| 90 |
char *key; |
|---|
| 91 |
int key_len; |
|---|
| 92 |
|
|---|
| 93 |
if (zend_parse_parameters (ZEND_NUM_ARGS ()TSRMLS_CC, "s", &key, &key_len) |
|---|
| 94 |
== FAILURE) |
|---|
| 95 |
return; |
|---|
| 96 |
|
|---|
| 97 |
if (eaccelerator_unlock (key, key_len TSRMLS_CC)) { |
|---|
| 98 |
RETURN_TRUE; |
|---|
| 99 |
} else { |
|---|
| 100 |
RETURN_FALSE; |
|---|
| 101 |
} |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
PHP_FUNCTION (eaccelerator_put) |
|---|
| 105 |
{ |
|---|
| 106 |
char *key; |
|---|
| 107 |
int key_len; |
|---|
| 108 |
zval *val; |
|---|
| 109 |
time_t ttl = 0; |
|---|
| 110 |
long where = eaccelerator_keys_cache_place; |
|---|
| 111 |
|
|---|
| 112 |
if (zend_parse_parameters (ZEND_NUM_ARGS ()TSRMLS_CC, "sz|ll", &key, |
|---|
| 113 |
&key_len, &val, &ttl, &where) == FAILURE) |
|---|
| 114 |
return; |
|---|
| 115 |
|
|---|
| 116 |
if (eaccelerator_put (key, key_len, val, ttl, where TSRMLS_CC)) { |
|---|
| 117 |
RETURN_TRUE; |
|---|
| 118 |
} else { |
|---|
| 119 |
RETURN_FALSE; |
|---|
| 120 |
} |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
PHP_FUNCTION (eaccelerator_get) |
|---|
| 124 |
{ |
|---|
| 125 |
char *key; |
|---|
| 126 |
int key_len; |
|---|
| 127 |
long where = eaccelerator_keys_cache_place; |
|---|
| 128 |
|
|---|
| 129 |
if (zend_parse_parameters (ZEND_NUM_ARGS ()TSRMLS_CC, |
|---|
| 130 |
"s|l", &key, &key_len, &where) == FAILURE) |
|---|
| 131 |
return; |
|---|
| 132 |
|
|---|
| 133 |
if (eaccelerator_get (key, key_len, return_value, where TSRMLS_CC)) { |
|---|
| 134 |
return; |
|---|
| 135 |
} else { |
|---|
| 136 |
RETURN_NULL (); |
|---|
| 137 |
} |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
PHP_FUNCTION (eaccelerator_rm) |
|---|
| 141 |
{ |
|---|
| 142 |
char *key; |
|---|
| 143 |
int key_len; |
|---|
| 144 |
long where = eaccelerator_keys_cache_place; |
|---|
| 145 |
|
|---|
| 146 |
if (zend_parse_parameters (ZEND_NUM_ARGS ()TSRMLS_CC, |
|---|
| 147 |
"s|l", &key, &key_len, &where) == FAILURE) |
|---|
| 148 |
return; |
|---|
| 149 |
|
|---|
| 150 |
if (eaccelerator_rm (key, key_len, where TSRMLS_CC)) { |
|---|
| 151 |
RETURN_TRUE; |
|---|
| 152 |
} else { |
|---|
| 153 |
RETURN_FALSE; |
|---|
| 154 |
} |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
PHP_FUNCTION (eaccelerator_gc) |
|---|
| 158 |
{ |
|---|
| 159 |
if (ZEND_NUM_ARGS () != 0) |
|---|
| 160 |
WRONG_PARAM_COUNT; |
|---|
| 161 |
|
|---|
| 162 |
eaccelerator_gc (TSRMLS_C); |
|---|
| 163 |
RETURN_TRUE; |
|---|
| 164 |
} |
|---|
| 165 |
#endif /* WITH_EACCELERATOR_SHM */ |
|---|
| 166 |
#endif /* HAVE_EACCELERATOR */ |
|---|