Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

validate caching connection details on "first turn on"

Started by danielrichter, July 05, 2022, 03:04:58 PM

Previous topic - Next topic


Dear SMF community,

I'm working on a new redis plugin (this time with phpredis extension, without using the predis library, since phpredis is around 6x faster than predis).

Can you explain me a way to validate the input (f.e. connection details for redis / Cache Directory) on the first time, when the plugin is switched to on (talking about my redis cache plugin).

I've already inspected the /Sources/Cache/APIs/FileBased.php implementation, but inside this you're using a fallback path / default path.
Using redis this won't be possible that easy. F.e. when the redis server is not running and the user enters the redis connection string it will cause whole SMF board to crash, same goes for the detail when he enters an invalid string.

Is there a way to validate connection details entered on "turn on" of the plugin?
I've tried to return false when catching an exception inside the connect() method of my Redis.php file, but this doesn't prevent SMF from crashing.

Any help highly appreciated.


You can handle whether the connection details are theoretically valid in the isSupported() method, again in the same vein as the others, if $test is true, verify that the dependencies exist and that's enough, if test is not true you can go on to validate the details are at least notionally valid (not an invalid string)

The return value of connect() is not checked according to Load.php, so the only thing you can actually do meaningfully is either a) hard abort whether you want to gracefully handle that with fatal_lang_error or not, or b) track that connection failed in the connector and simply early-return from getData() and putData() if you want to let it continue running.


Thank you @Arantor for the quick reply.
Think I would stick to a hard abort. Did you mean just a die("redis connection check invalid"); statement inside the connect() method?

Maybe I should request more validation as a feature request.


No, I specifically said fatal_lang_error if that's the route you want to take.


I created a pr which could be a guide line for person how like to add redis in the exists smf version,
the pr i guess will take some time to get in the release:


good stuff. it works via a password port, but does not want to use a socket file.

how to set the path to the socket file?


Quote from: meccep45 on May 17, 2023, 10:18:53 AMredis.sock

FastCGI sent in stderr: "PHP message: PHP Warning:  Redis::connect(): php_network_getaddresses: getaddrinfo for  failed: Name or service not known in /opt/share/www/Sources/Cache/APIs/RedisCache.php on line 84"