php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56574 memcache_add triggers E_NOTICE when item exists
Submitted: 2005-10-03 06:33 UTC Modified: 2005-10-03 07:26 UTC
From: mikael at chl dot chalmers dot se Assigned:
Status: Not a bug Package: memcache (PECL)
PHP Version: 4.4.0 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mikael at chl dot chalmers dot se
New email:
PHP Version: OS:

 

 [2005-10-03 06:33 UTC] mikael at chl dot chalmers dot se
Description:
------------
memcache_add() triggers an E_NOTICE when item exists instead of just returning FALSE

See memcache.c line 604, perhaps one could check if "add" has been executed and treat the result differently if so

Using PHP 4.4.0 actually, the drop-down lacked that option though

Btw, is there any development going on to include multiple server support?

Reproduce code:
---------------
error_reporting(E_ALL);
$conn = memcache_pconnect('localhost', 11211);
memcache_set($conn, 'somekey', 'foo');
memcache_add($conn, 'somekey', 'foobar');

Expected result:
----------------
No notice triggered, but memcache_add should return FALSE

Actual result:
--------------
"Notice: memcache_add(): an error occured while trying to store the item on the server" and returns FALSE

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-03 06:45 UTC] tony2001 at phpclub dot net
This is the way it works, as the user should know WHY exactly it fails.
If you don't want to see the errmsg - use error_reporting() to turn On E_NOTICE's.

>Btw, is there any development going on to include multiple server support?
Feel free to pay for my time.
 [2005-10-03 07:03 UTC] mikael at chl dot chalmers dot se
Isn't E_NOTICE supposed to indicate some kind of error condition. When memcache_add fails to add the key because it already exists this is the expected behaviour and the documentation says it will return false if so:

http://se.php.net/memcache_add
 "Memcache::add() returns FALSE if such key already exist" 

Besides, the error message doesn't include any information on the specific cause of the error, just that some generic error occured. 

Calling memcache_add with the @ operator would prevent us from seeing other errors and setting the error level to above E_NOTICE is tricky when using custom error handlers.

>> Btw, is there any development going on to include multiple server support?
> Feel free to pay for my time.

Would contributed code to this end be interesting and perhaps accepted into the distribution?
 [2005-10-03 07:26 UTC] tony2001 at phpclub dot net
>Isn't E_NOTICE supposed to indicate some kind of error condition.

Yes, it does.

>Besides, the error message doesn't include any information
>on the specific cause of the error, just that some generic 
>error occured. 

Since memcached doesn't return any error info, I can't figure out why exactly it failed to write the item, so 
the error message is the only way to tell that "something went wrong".

>Would contributed code to this end be interesting and
>perhaps accepted into the distribution?

Didn't get the question.
Please use private mail.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 02:01:30 2024 UTC