0

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...

2
  • no. look at it this way - php has to be able to load the session file to update that session key with the upload progress, and do this completely independently of your code. if you're using a custom handler, PHP would somehow have to be able to do everything your handler does, but without ever knowing your code. Commented Jan 16, 2013 at 15:48
  • I've since come to the same conclusion! thx Commented Jan 16, 2013 at 16:36

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

In Fedora/Centos you have to be careful because there is an apache file conf.d/php.conf that overwrites the php.ini settings. The best way for me was to make the settings in the .htacess file so both the application and the progress uploader will use the same session config.
0

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.