{"action":"created","issue":{"url":"https://api.github.com/repos/phpredis/phpredis/issues/1432","repository_url":"https://api.github.com/repos/phpredis/phpredis","labels_url":"https://api.github.com/repos/phpredis/phpredis/issues/1432/labels{/name}","comments_url":"https://api.github.com/repos/phpredis/phpredis/issues/1432/comments","events_url":"https://api.github.com/repos/phpredis/phpredis/issues/1432/events","html_url":"https://github.com/phpredis/phpredis/issues/1432","id":371127364,"node_id":"MDU6SXNzdWUzNzExMjczNjQ=","number":1432,"title":"[Possible Bug] PhpRedis keeps crashing PHP when a key expires","user":{"login":"ProjectCleverWeb","id":1664987,"node_id":"MDQ6VXNlcjE2NjQ5ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1664987?v=4","gravatar_id":"","url":"https://api.github.com/users/ProjectCleverWeb","html_url":"https://github.com/ProjectCleverWeb","followers_url":"https://api.github.com/users/ProjectCleverWeb/followers","following_url":"https://api.github.com/users/ProjectCleverWeb/following{/other_user}","gists_url":"https://api.github.com/users/ProjectCleverWeb/gists{/gist_id}","starred_url":"https://api.github.com/users/ProjectCleverWeb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ProjectCleverWeb/subscriptions","organizations_url":"https://api.github.com/users/ProjectCleverWeb/orgs","repos_url":"https://api.github.com/users/ProjectCleverWeb/repos","events_url":"https://api.github.com/users/ProjectCleverWeb/events{/privacy}","received_events_url":"https://api.github.com/users/ProjectCleverWeb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-17T15:09:56Z","updated_at":"2018-10-17T15:48:51Z","closed_at":null,"author_association":"NONE","body":"### Expected behaviour\r\nThe millisecond a key expires `get()` should return `FALSE`.\r\n\r\n### Actual behaviour\r\nThe millisecond a key expires and `get()` is called, PHP suddenly exits without showing/logging an error (or running shutdown behavior)\r\n\r\n### I'm seeing this behaviour on\r\n- OS: Amazon Linux (fork of RHEL/Fedora)\r\n- Redis: 4.0.10 via AWS ElastiCache (Clustered, 1 Shard/2 Nodes)\r\n- PHP: 7.0.31 (Running as PHP-FPM)\r\n- phpredis: 3.1.1-1.1.amzn1\r\n\r\n### Steps to reproduce, backtrace or example script\r\nAttempt to `get()` a key several times at about the time it is set to expire. I know that it is specifically `get()` that's failing, because I had PHP write to a text file before and after each interaction with Redis, including connecting to Redis.\r\n\r\nIn my particular case, the expire is set to 10 seconds and if a request happens exactly 10 seconds later, PHP-FPM exits without showing an error (or running shutdown behavior) and resets the connection to Nginx, which nginx then responds with a 502 Bad Gateway error. The API that I am integrating Redis into handles about 5-10 requests per second during peak hours, so this would become a common error.\r\n\r\nThe real version of the below code is a class called by an endpoint, but for simplicity's sake I have removed code that isn't related to PhpRedis:\r\n\r\n```php\r\nfunction cache_store(string $key, $value, int $lifespan = 10) {\r\n\t// [not shown] checking if we successfully connected to Redis, if both $key\r\n\t// and $lifespan are valid, and if we can serialize $value\r\n\t\r\n\t// $connection is an instance of RedisCluster\r\n\tglobal $connection;\r\n\t\r\n\treturn $connection->setEx($key, $lifespan, serialize($value));\r\n}\r\n\r\nfunction cache_exists(string $key) {\r\n\t// [not shown] checking if we successfully connected to Redis and if $key is\r\n\t// valid\r\n\t\r\n\t// $connection is an instance of RedisCluster\r\n\tglobal $connection;\r\n\t\r\n\treturn $connection->exists($key);\r\n}\r\n\r\nfunction cache_read(string $key) {\r\n\t// Checks if connected & valid key & exists\r\n\tif (!cache_exists($key)) {\r\n\t\treturn NULL;\r\n\t}\r\n\t\r\n\t// $connection is an instance of RedisCluster\r\n\tglobal $connection;\r\n\t\r\n\t$value = $connection->get($key);\r\n\tif (!$value) {\r\n\t\treturn NULL;\r\n\t}\r\n\treturn unserialize($value);\r\n}\r\n\r\ntry {\r\n\t$connection = new \\RedisCluster(NULL, array('redis.aws.example.com'),1,1);\r\n} catch (\\Exception $e) {\r\n\techo $e->getMessage();\r\n\texit;\r\n}\r\n$cache_key = 'core:time';\r\n$time      = cache_read($cache_key);\r\nif (is_null($time)) {\r\n\t$time = time();\r\n\tcache_store($cache_key, $time, 10);\r\n}\r\n\r\nvar_dump($time);\r\n```\r\n\r\n### I've checked\r\n- [ X ] There is no similar issue from other users\r\n- [ **not sure** ] Issue isn't fixed in `develop` branch\r\n"},"comment":{"url":"https://api.github.com/repos/phpredis/phpredis/issues/comments/430683036","html_url":"https://github.com/phpredis/phpredis/issues/1432#issuecomment-430683036","issue_url":"https://api.github.com/repos/phpredis/phpredis/issues/1432","id":430683036,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDY4MzAzNg==","user":{"login":"ProjectCleverWeb","id":1664987,"node_id":"MDQ6VXNlcjE2NjQ5ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1664987?v=4","gravatar_id":"","url":"https://api.github.com/users/ProjectCleverWeb","html_url":"https://github.com/ProjectCleverWeb","followers_url":"https://api.github.com/users/ProjectCleverWeb/followers","following_url":"https://api.github.com/users/ProjectCleverWeb/following{/other_user}","gists_url":"https://api.github.com/users/ProjectCleverWeb/gists{/gist_id}","starred_url":"https://api.github.com/users/ProjectCleverWeb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ProjectCleverWeb/subscriptions","organizations_url":"https://api.github.com/users/ProjectCleverWeb/orgs","repos_url":"https://api.github.com/users/ProjectCleverWeb/repos","events_url":"https://api.github.com/users/ProjectCleverWeb/events{/privacy}","received_events_url":"https://api.github.com/users/ProjectCleverWeb/received_events","type":"User","site_admin":false},"created_at":"2018-10-17T15:48:51Z","updated_at":"2018-10-17T15:48:51Z","author_association":"NONE","body":"After further research, this is still happening but it's probably not related to expired keys. My first few tests just happen to occur at about the time of expire. I was able to recreate this issue where it happened only 2 seconds after a key with a 10 second expire was created."}}
{"actor":{"display_login":"ProjectCleverWeb"}}