News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

validate caching connection details on "first turn on"

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

Previous topic - Next topic

danielrichter

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.

Arantor

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.

danielrichter

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.

Arantor

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

albertlast

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: https://github.com/SimpleMachines/SMF/pull/7518

Advertisement: