PHP: How to use session on one page while another page with session is loading

前端 未结 1 1037
暖寄归人
暖寄归人 2021-01-17 00:00

I am using CURL to download a large file from an external url and save it on my server. This can take up to few minutes. While the download is running I\'m using the curl_se

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-17 00:37

    You have the classic problem with filesystem-backed sessions. Your upload script locks the session backing file for its duration, so it's impossible to get access to the session information until it releases the lock.

    There are several possible solutions here, but the easiest one would be for your upload script to periodically release the session and lock it again; this would leave opportunity for your progress script to read the session in the meantime.

    To release the session lock, call session_write_close at any point from your upload script. This leaves you without access to session variables until you call session_start again later on. You can repeat this cycle as much as you like.

    There are also other, more capable solutions. For example you could move the progress information to some storage mechanism that does not stay locked for the duration of a script; you can identify each user's information based on their session id (you don't need to start the session to get its ID, if one exists).

    0 讨论(0)
提交回复
热议问题