PHP Session Upload使用自定义会话处理程序的进度
PHP5.4 provides Session Upload Progress indication. I have noticed that it works, but only if session.save_handler
is set to files
, and session.name
is not modified. As soon as I modify these values, the superglobal $_SESSION['upload_progress_<key>']
is empty / not set.
Is it possible to provide session upload progress indication, but with custom session handling? Even save handler memcache
does not work...
PHP5.4提供会话上传进度指示。 我注意到它有效,但只有 是否可以提供会话 上传进度指示,但自定义会话处理? 甚至保存处理程序 session.save_handler code>设置为
files code>,并且
session.name code>不被修改。 一旦我修改了这些值,超级全局
$ _ SESSION ['upload_progress_&lt; key&gt;'] code>就会为空/未设置。 p>
memcache code>也不起作用...... p>
div>
As @Marc points out: Session Upload Progress indication is running while the upload is ongoing, and before control is handed over to a user's PHP code. As a result, the php upload handler uses configuration data set in the .ini
files, and can only use modules that are available at that time.
It is possible to use the memcache
save-handler, or specify a different session name, as long as everything is configured in an .ini
file:
session.save_handler = memcache
session.save_path = "tcp://198.51.100.1:11211?persistent=1&weight=1&timeout=1&retry_interval=15,tcp://198.51.100.2:11211?persistent=1&weight=1&timeout=1&retry_interval=15"
session.name = "myUploadProgressSession"
It's not possible to specify these settings via ini_set("session.save_handler", "memcache")
in code, since this is executed too late.
While it is true that session.upload_progress will work only if session.save_handler is set to files, this can nonetheless be managed. In your ajax call where you are checking for the upload progress, simply avoid using the user session.save_handler. When the upload is complete, you can remove the unwanted sess_xxx files which will be left in your temp directory by doing the following in your setup for your user sessions:
//setup the garbage collection parameters which will be used by both the user and file session.save_handler
ini_set('session.gc_maxlifetime', $this->tempo);
ini_set('session.gc_probability', '1');
ini_set('session.gc_divisor', '100');
//destroy the sess_xxx files left from the file session.save_handler for *this* session
//and let the GC remove any which are left over from the file save_handler for *other sessions*
ini_set('session.save_handler', 'files');
session_start();
session_unset();
session_destroy(); //this will remove the sess_xxx temp files
//now set the handler to user defined
ini_set('session.save_handler', 'user');