note 128197 added to function.session-start

From: Date: Wed, 08 Feb 2023 02:19:15 +0000
Subject: note 128197 added to function.session-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-220154@lists.php.net to get a copy of this message
Be warned of another issue with blocking sessions: if you want to call an external program (or use an external service) that needs to access your website using the same session. For example I am printing a page as a PDF. I can just save the web page as a HTML file. But the images in the HTML are also private and require the current user session to be seen. What will happen is that this program might hang indefinitely (or timeout) as session_start waits for the parent PHP process to release the lock. And session_start doesn't obey max_execution_time (as documented in this bug: https://bugs.php.net/bug.php?id=72345 ), so this will effectively kill the server after a few requests, as each one will be hanging forever It's the same if you use an external HTTP service: <?php $pdf = file_get_contents('http://pdf.website.tld/?url=http://website.tld/print.php'); ?> The service will wait for the website host to release the lock, but it can't as it is waiting for the PDF service to finish... The nice solution is to release the lock immediately by calling session_write_close after session_start, and when you need to write to the session you do the same again, but as noted it has its own issues. Using a custom session handler is probably the best solution. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 93.23.17.71) ---- Manual Page -- https://php.net/manual/en/function.session-start.php Edit -- https://main.php.net/note/edit/128197 Del: integrated -- https://main.php.net/note/delete/128197/integrated Del: useless -- https://main.php.net/note/delete/128197/useless Del: bad code -- https://main.php.net/note/delete/128197/bad+code Del: spam -- https://main.php.net/note/delete/128197/spam Del: non-english -- https://main.php.net/note/delete/128197/non-english Del: in docs -- https://main.php.net/note/delete/128197/in+docs Del: other reasons-- https://main.php.net/note/delete/128197 Reject -- https://main.php.net/note/reject/128197 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220154) next »