Avoid updating upload progress information too frequently on high transfert

rate.
[DOC] (HEAD only)
Added session.upload_progress.min_freq
http://wiki.php.net/rfc/session_upload_progress
This commit is contained in:
Arnaud Le Blanc 2008-09-27 09:08:41 +00:00
parent 823eb94e88
commit 429b4293bb
3 changed files with 31 additions and 14 deletions

View File

@ -103,6 +103,7 @@ typedef struct _php_session_rfc1867_progress {
zval key;
long update_step;
long next_update;
double last_update_time;
zval *data;
size_t content_length;
zval *post_bytes_processed;
@ -166,6 +167,7 @@ typedef struct _php_ps_globals {
zstr rfc1867_prefix;
zstr rfc1867_name;
long rfc1867_freq;
double rfc1867_min_freq;
php_session_rfc1867_progress *rfc1867_progress;
} php_ps_globals;

View File

@ -696,6 +696,8 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("session.upload_progress.name",
"PHP_SESSION_UPLOAD_PROGRESS", ZEND_INI_PERDIR, OnUpdateUTF8String, rfc1867_name, php_ps_globals, ps_globals)
STD_PHP_INI_ENTRY("session.upload_progress.freq", "1%", ZEND_INI_PERDIR, OnUpdateRfc1867Freq, rfc1867_freq, php_ps_globals, ps_globals)
STD_PHP_INI_ENTRY("session.upload_progress.min_freq",
"0", ZEND_INI_PERDIR, OnUpdateReal, rfc1867_min_freq,php_ps_globals, ps_globals)
/* Commented out until future discussion */
/* PHP_INI_ENTRY("session.encode_sources", "globals,track", PHP_INI_ALL, NULL) */
@ -2150,9 +2152,29 @@ static inline void php_session_rfc1867_early_find_sid(php_session_rfc1867_progre
}
} /* }}} */
static inline void php_session_rfc1867_update(php_session_rfc1867_progress *progress TSRMLS_DC) /* {{{ */
static inline void php_session_rfc1867_update(php_session_rfc1867_progress *progress, int force_update TSRMLS_DC) /* {{{ */
{
zval **progress_ary, **cancel_upload;
if (!force_update) {
if (Z_LVAL_P(progress->post_bytes_processed) < progress->next_update) {
return;
}
#ifdef HAVE_GETTIMEOFDAY
if (PS(rfc1867_min_freq) > 0.0) {
struct timeval tv = {0};
double dtv;
gettimeofday(&tv, NULL);
dtv = (double) tv.tv_sec + tv.tv_usec / 1000000.0;
if ((dtv - progress->last_update_time) < PS(rfc1867_min_freq)) {
return;
}
progress->last_update_time = dtv;
}
#endif
progress->next_update = Z_LVAL_P(progress->post_bytes_processed) + progress->update_step;
}
php_session_initialize(TSRMLS_C);
PS(session_status) = php_session_active;
IF_SESSION_VARS() {
@ -2265,6 +2287,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
progress->update_step = progress->content_length * -PS(rfc1867_freq) / 100;
}
progress->next_update = 0;
progress->last_update_time = 0.0;
ALLOC_INIT_ZVAL(progress->data);
array_init(progress->data);
@ -2301,10 +2324,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed;
if (data->post_bytes_processed >= progress->next_update) {
php_session_rfc1867_update(progress TSRMLS_CC);
progress->next_update = data->post_bytes_processed + progress->update_step;
}
php_session_rfc1867_update(progress, 0 TSRMLS_CC);
}
break;
case MULTIPART_EVENT_FILE_DATA: {
@ -2317,10 +2337,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
Z_LVAL_P(progress->current_file_bytes_processed) = data->offset + data->length;
Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed;
if (data->post_bytes_processed >= progress->next_update) {
php_session_rfc1867_update(progress TSRMLS_CC);
progress->next_update = data->post_bytes_processed + progress->update_step;
}
php_session_rfc1867_update(progress, 0 TSRMLS_CC);
}
break;
case MULTIPART_EVENT_FILE_END: {
@ -2338,10 +2355,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed;
if (data->post_bytes_processed >= progress->next_update) {
php_session_rfc1867_update(progress TSRMLS_CC);
progress->next_update = data->post_bytes_processed + progress->update_step;
}
php_session_rfc1867_update(progress, 0 TSRMLS_CC);
}
break;
case MULTIPART_EVENT_END: {
@ -2350,7 +2364,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
if (Z_TYPE(progress->sid) && Z_TYPE(progress->key)) {
add_ascii_assoc_bool_ex(progress->data, "done", sizeof("done"), 1);
Z_LVAL_P(progress->post_bytes_processed) = data->post_bytes_processed;
php_session_rfc1867_update(progress TSRMLS_CC);
php_session_rfc1867_update(progress, 1 TSRMLS_CC);
php_rshutdown_session_globals(TSRMLS_C);
}

View File

@ -13,6 +13,7 @@ session.upload_progress.enabled=1
session.upload_progress.prefix=upload_progress_
session.upload_progress.name=PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.freq=1%
session.upload_progress.min_freq=0.000000001
--SKIPIF--
<?php include('skipif.inc'); ?>
--COOKIE--