PHP Memcached extension result codes
Asked Answered
P

2

11

I'm using the Memcached::set() and Memcached::get() methods. The documentation states that if an error occurs, or, in general, to check the status of these methods, I should call Memcached::getResultCode().

Where can I find a complete list of result codes, with both what the result code represents and what its numeric values is?

The best thing I found so far is in some comments from Memcached::getResultCode(), but the list doesn't include 8 and 47. Another list is in the Memcached Predefined Constants page, but it doesn't include the numeric values.

Passably answered 28/1, 2012 at 4:21 Comment(0)
P
21

I found the error codes in the libmemcached source code.

 0 = MEMCACHED_SUCCESS
 1 = MEMCACHED_FAILURE
 2 = MEMCACHED_HOST_LOOKUP_FAILURE // getaddrinfo() and getnameinfo() only
 3 = MEMCACHED_CONNECTION_FAILURE
 4 = MEMCACHED_CONNECTION_BIND_FAILURE // DEPRECATED see MEMCACHED_HOST_LOOKUP_FAILURE
 5 = MEMCACHED_WRITE_FAILURE
 6 = MEMCACHED_READ_FAILURE
 7 = MEMCACHED_UNKNOWN_READ_FAILURE
 8 = MEMCACHED_PROTOCOL_ERROR
 9 = MEMCACHED_CLIENT_ERROR
10 = MEMCACHED_SERVER_ERROR // Server returns "SERVER_ERROR"
11 = MEMCACHED_ERROR // Server returns "ERROR"
11 = MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE = MEMCACHED_ERROR
12 = MEMCACHED_DATA_EXISTS
13 = MEMCACHED_DATA_DOES_NOT_EXIST
14 = MEMCACHED_NOTSTORED
15 = MEMCACHED_STORED
16 = MEMCACHED_NOTFOUND
17 = MEMCACHED_MEMORY_ALLOCATION_FAILURE
18 = MEMCACHED_PARTIAL_READ
19 = MEMCACHED_SOME_ERRORS
20 = MEMCACHED_NO_SERVERS
21 = MEMCACHED_END
22 = MEMCACHED_DELETED
23 = MEMCACHED_VALUE
24 = MEMCACHED_STAT
25 = MEMCACHED_ITEM
26 = MEMCACHED_ERRNO
27 = MEMCACHED_FAIL_UNIX_SOCKET // DEPRECATED
28 = MEMCACHED_NOT_SUPPORTED
29 = MEMCACHED_NO_KEY_PROVIDED /* Deprecated. Use MEMCACHED_BAD_KEY_PROVIDED! */
30 = MEMCACHED_FETCH_NOTFINISHED
31 = MEMCACHED_TIMEOUT
32 = MEMCACHED_BUFFERED
33 = MEMCACHED_BAD_KEY_PROVIDED
34 = MEMCACHED_INVALID_HOST_PROTOCOL
35 = MEMCACHED_SERVER_MARKED_DEAD
36 = MEMCACHED_UNKNOWN_STAT_KEY
37 = MEMCACHED_E2BIG
38 = MEMCACHED_INVALID_ARGUMENTS
39 = MEMCACHED_KEY_TOO_BIG
40 = MEMCACHED_AUTH_PROBLEM
41 = MEMCACHED_AUTH_FAILURE
42 = MEMCACHED_AUTH_CONTINUE
43 = MEMCACHED_PARSE_ERROR
44 = MEMCACHED_PARSE_USER_ERROR
45 = MEMCACHED_DEPRECATED
46 = MEMCACHED_IN_PROGRESS
47 = MEMCACHED_SERVER_TEMPORARILY_DISABLED
48 = MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE
49 = MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */
Passably answered 28/1, 2012 at 4:47 Comment(3)
Excellent. Here's a pastebin I just created that links the libmemcached return codes listed above to the PHP extension constants. It's pulled directly from the php_memcached.c extension code. Hopefully our combined efforts can save people some time down the road :)Faina
This one is so awesome I've added it as a comment to the Memcached constants page. There were a comment there but quite outdated. br2.php.net/manual/en/memcached.constants.php#118557Pavonine
hilariously this is the only place on the internet that has the list of numbers with the error string. i'm coming here because there is a python library pylibmc that gave me an error code but did not provide the error string. even the documentation lists the error string only wihtout the error number.Carvalho
S
0

As of PHP 8.2 I get these:

0:      Memcached::RES_SUCCESS
1:      Memcached::RES_FAILURE
2:      Memcached::RES_HOST_LOOKUP_FAILURE
5:      Memcached::RES_WRITE_FAILURE
7:      Memcached::RES_UNKNOWN_READ_FAILURE
8:      Memcached::RES_PROTOCOL_ERROR
9:      Memcached::RES_CLIENT_ERROR
10:     Memcached::RES_SERVER_ERROR
11:     Memcached::RES_CONNECTION_SOCKET_CREATE_FAILURE
12:     Memcached::RES_DATA_EXISTS
14:     Memcached::RES_NOTSTORED
15:     Memcached::RES_STORED
16:     Memcached::RES_NOTFOUND
17:     Memcached::RES_MEMORY_ALLOCATION_FAILURE
18:     Memcached::RES_PARTIAL_READ
19:     Memcached::RES_SOME_ERRORS
20:     Memcached::RES_NO_SERVERS
21:     Memcached::RES_END
22:     Memcached::RES_DELETED
24:     Memcached::RES_STAT
25:     Memcached::RES_ITEM
26:     Memcached::RES_ERRNO
28:     Memcached::RES_NOT_SUPPORTED
30:     Memcached::RES_FETCH_NOTFINISHED
31:     Memcached::RES_TIMEOUT
32:     Memcached::RES_BUFFERED
33:     Memcached::RES_BAD_KEY_PROVIDED
34:     Memcached::RES_INVALID_HOST_PROTOCOL
35:     Memcached::RES_SERVER_MARKED_DEAD
36:     Memcached::RES_UNKNOWN_STAT_KEY
37:     Memcached::RES_E2BIG
39:     Memcached::RES_KEY_TOO_BIG
40:     Memcached::RES_AUTH_PROBLEM
41:     Memcached::RES_AUTH_FAILURE
42:     Memcached::RES_AUTH_CONTINUE
47:     Memcached::RES_SERVER_TEMPORARILY_DISABLED
48:     Memcached::RES_SERVER_MEMORY_ALLOCATION_FAILURE
Sharp answered 2/6, 2023 at 8:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.