Session_write_close in Commerce import example script

Continuing the discussion from Example product import script:
Does any one have an idea if this line is required indeed?

I can imagine that MODX may open session but in PHP8.1 and MODX 2.8.5 it is throwing PHP warning: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: /tmp/sessions)

It’s a best practice to call that before an exit() to make sure sessions are written and closed.

If it is executed when no session is opened it can cause a warning (previously in PHP7 that was just a notice) and if you’re sure you will not run it from anywhere that has a session, you can safely remove it. To give an example, the import script can be run from a snippet so that may have an active session.

1 Like

Thanks for full details and example. Have a wonderful day