当我在 CentOS 6.4 上从命令行运行以下程序时,我得到了预期的结果,但是当我将它作为 Apache cgi 运行时,我Couldn't store key: SYSTEM ERROR
出错了。我正在通过同一个用户运行 Memcached、Apache 和程序。
我可能做错了什么?
#include<stdio.h>
#include<string.h>
#include <libmemcached/memcached.h>
int main(int argc, char **argv) {
memcached_server_st *servers = NULL;
memcached_st *memc;
memcached_return rc;
char *key= "keystring";
char *value= "keyvalue";
char *key1= "keystring1";
char *value1= "keyvalue1 ";
memc= memcached_create(NULL);
servers= memcached_server_list_append(servers, "localhost", 11211, &rc);
rc= memcached_server_push(memc, servers);
printf("Content-Type: text/plain;charset=us-ascii\n\n");
if (rc == MEMCACHED_SUCCESS)
printf("Added server successfully\n");
else
printf("Couldn't add server: %s\n",memcached_strerror(memc, rc));
rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0);
if (rc == MEMCACHED_SUCCESS)
printf("Key stored successfully\n");
else
printf("Couldn't store key: %s\n",memcached_strerror(memc, rc));
char *keys[]= {"keystring", "keystring1"};
size_t key_length[]= {9, 10};
unsigned int x;
uint32_t flags;
char return_key[MEMCACHED_MAX_KEY];
size_t return_key_length;
char *return_value;
size_t return_value_length;
rc= memcached_mget(memc, keys, key_length, 2);
x= 0;
if (rc == MEMCACHED_SUCCESS)
{
while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
&return_value_length, &flags, &rc)))
{
if (rc == MEMCACHED_SUCCESS)
{
printf("Key %s returned %s\n",return_key, return_value);
}
}
}
return 0;
}