Skip to content

Commit f29eae1

Browse files
committed
Move timeout code to Zend, allow Win32 timeouts
@- Implemented max_execution_time under Win32 (Zeev)
1 parent e3ae196 commit f29eae1

File tree

6 files changed

+21
-62
lines changed

6 files changed

+21
-62
lines changed

ext/mysql/php_mysql.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void _close_mysql_plink(MYSQL *link)
210210
static PHP_INI_MH(OnMySQLPort)
211211
{
212212
MySLS_FETCH();
213-
213+
214214
if (new_value==NULL) { /* default port */
215215
#ifndef PHP_WIN32
216216
struct servent *serv_ptr;
@@ -236,11 +236,12 @@ static PHP_INI_MH(OnMySQLPort)
236236
PHP_INI_BEGIN()
237237
STD_PHP_INI_BOOLEAN("mysql.allow_persistent", "1", PHP_INI_SYSTEM, OnUpdateInt, allow_persistent, zend_mysql_globals, mysql_globals)
238238
STD_PHP_INI_ENTRY_EX("mysql.max_persistent", "-1", PHP_INI_SYSTEM, OnUpdateInt, max_persistent, zend_mysql_globals, mysql_globals, display_link_numbers)
239-
STD_PHP_INI_ENTRY_EX("mysql.max_links", "-1", PHP_INI_SYSTEM, OnUpdateInt, max_links, zend_mysql_globals, mysql_globals, display_link_numbers)
240-
STD_PHP_INI_ENTRY("mysql.default_host", NULL, PHP_INI_ALL, OnUpdateString, default_host, zend_mysql_globals, mysql_globals)
241-
STD_PHP_INI_ENTRY("mysql.default_user", NULL, PHP_INI_ALL, OnUpdateString, default_user, zend_mysql_globals, mysql_globals)
242-
STD_PHP_INI_ENTRY("mysql.default_password", NULL, PHP_INI_ALL, OnUpdateString, default_password, zend_mysql_globals, mysql_globals)
243-
PHP_INI_ENTRY("mysql.default_port", NULL, PHP_INI_ALL, OnMySQLPort)
239+
STD_PHP_INI_ENTRY_EX("mysql.max_links", "-1", PHP_INI_SYSTEM, OnUpdateInt, max_links, zend_mysql_globals, mysql_globals, display_link_numbers)
240+
STD_PHP_INI_ENTRY("mysql.default_host", NULL, PHP_INI_ALL, OnUpdateString, default_host, zend_mysql_globals, mysql_globals)
241+
STD_PHP_INI_ENTRY("mysql.default_user", NULL, PHP_INI_ALL, OnUpdateString, default_user, zend_mysql_globals, mysql_globals)
242+
STD_PHP_INI_ENTRY("mysql.default_password", NULL, PHP_INI_ALL, OnUpdateString, default_password, zend_mysql_globals, mysql_globals)
243+
PHP_INI_ENTRY("mysql.default_port", NULL, PHP_INI_ALL, OnMySQLPort)
244+
STD_PHP_INI_ENTRY("mysql.default_socket", NULL, PHP_INI_ALL, OnUpdateStringUnempty, default_socket, zend_mysql_globals, mysql_globals)
244245
PHP_INI_END()
245246

246247

@@ -311,14 +312,16 @@ PHP_MINFO_FUNCTION(mysql)
311312

312313
static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent)
313314
{
314-
char *user,*passwd,*host,*socket=NULL,*tmp;
315+
char *user,*passwd,*host,*socket,*tmp;
315316
char *hashed_details;
316317
int hashed_details_length,port = MYSQL_PORT;
317318
MYSQL *mysql;
318319
void (*handler) (int);
319320
MySLS_FETCH();
320321
PLS_FETCH();
321322

323+
socket = MySG(default_socket);
324+
322325
if (PG(sql_safe_mode)) {
323326
if (ZEND_NUM_ARGS()>0) {
324327
php_error(E_NOTICE,"SQL safe mode in effect - ignoring host/user/password information");

ext/mysql/php_mysql.h

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ ZEND_BEGIN_MODULE_GLOBALS(mysql)
8282
long allow_persistent;
8383
long default_port;
8484
char *default_host, *default_user, *default_password;
85+
char *default_socket;
8586
ZEND_END_MODULE_GLOBALS(mysql);
8687

8788
#ifdef ZTS

main/main.c

+4-55
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ static MUTEX_T global_lock;
9696

9797

9898
static void php_build_argv(char *s, zval *track_vars_array ELS_DC PLS_DC);
99-
static void php_timeout(int dummy);
100-
static void php_set_timeout(long seconds);
10199

102100
void *gLock; /*mutex variable */
103101

@@ -441,55 +439,6 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
441439
}
442440

443441

444-
static long php_timeout_seconds;
445-
446-
#ifdef HAVE_SETITIMER
447-
static void php_timeout(int dummy)
448-
{
449-
PLS_FETCH();
450-
451-
PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
452-
php_error(E_ERROR, "Maximum execution time of %d second%s exceeded",
453-
php_timeout_seconds, php_timeout_seconds == 1 ? "" : "s");
454-
}
455-
#endif
456-
457-
/* This one doesn't exists on QNX */
458-
#ifndef SIGPROF
459-
#define SIGPROF 27
460-
#endif
461-
462-
static void php_set_timeout(long seconds)
463-
{
464-
#ifdef PHP_WIN32
465-
#else
466-
# ifdef HAVE_SETITIMER
467-
struct itimerval t_r; /* timeout requested */
468-
469-
t_r.it_value.tv_sec = seconds;
470-
t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
471-
472-
php_timeout_seconds = seconds;
473-
setitimer(ITIMER_PROF, &t_r, NULL);
474-
signal(SIGPROF, php_timeout);
475-
# endif
476-
#endif
477-
}
478-
479-
480-
static void php_unset_timeout(void)
481-
{
482-
#ifdef PHP_WIN32
483-
#else
484-
# ifdef HAVE_SETITIMER
485-
struct itimerval no_timeout;
486-
487-
no_timeout.it_value.tv_sec = no_timeout.it_value.tv_usec = no_timeout.it_interval.tv_sec = no_timeout.it_interval.tv_usec = 0;
488-
489-
setitimer(ITIMER_PROF, &no_timeout, NULL);
490-
# endif
491-
#endif
492-
}
493442

494443
/* {{{ proto void set_time_limit(int seconds)
495444
Sets the maximum time a script can run */
@@ -518,8 +467,8 @@ PHP_FUNCTION(set_time_limit)
518467
should work fine. Is this FIXME a WIN32 problem? Is
519468
there no way to do per-thread timers on WIN32?
520469
*/
521-
php_unset_timeout();
522-
php_set_timeout(Z_LVAL_PP(new_timeout));
470+
zend_unset_timeout();
471+
zend_set_timeout(Z_LVAL_PP(new_timeout));
523472
}
524473
/* }}} */
525474

@@ -654,7 +603,7 @@ int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC)
654603
virtual_cwd_activate(SG(request_info).path_translated);
655604
#endif
656605

657-
php_set_timeout(PG(max_execution_time));
606+
zend_set_timeout(PG(max_execution_time));
658607

659608
if (PG(expose_php)) {
660609
sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
@@ -703,7 +652,7 @@ void php_request_shutdown(void *dummy)
703652
sapi_deactivate(SLS_C);
704653

705654
shutdown_memory_manager(CG(unclean_shutdown), 0);
706-
php_unset_timeout();
655+
zend_unset_timeout();
707656

708657
global_unlock();
709658
}

php.ini-dist

+2
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ mysql.default_port = ; default port number for mysql_connect(). If unset,
300300
; mysql_connect() will use the $MYSQL_TCP_PORT, or the mysql-tcp
301301
; entry in /etc/services, or the compile-time defined MYSQL_PORT
302302
; (in that order). Win32 will only look at MYSQL_PORT.
303+
mysql.default_socket = ; default socket name for local MySQL connects. If empty, uses the built-in
304+
; MySQL defaults
303305
mysql.default_host = ; default host for mysql_connect() (doesn't apply in safe mode)
304306
mysql.default_user = ; default user for mysql_connect() (doesn't apply in safe mode)
305307
mysql.default_password = ; default password for mysql_connect() (doesn't apply in safe mode)

php.ini-optimized

+2
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ mysql.default_port = ; default port number for mysql_connect(). If unset,
288288
; mysql_connect() will use the $MYSQL_TCP_PORT, or the mysql-tcp
289289
; entry in /etc/services, or the compile-time defined MYSQL_PORT
290290
; (in that order). Win32 will only look at MYSQL_PORT.
291+
mysql.default_socket = ; default socket name for local MySQL connects. If empty, uses the built-in
292+
; MySQL defaults
291293
mysql.default_host = ; default host for mysql_connect() (doesn't apply in safe mode)
292294
mysql.default_user = ; default user for mysql_connect() (doesn't apply in safe mode)
293295
mysql.default_password = ; default password for mysql_connect() (doesn't apply in safe mode)

php.ini-recommended

+2
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ mysql.default_port = ; default port number for mysql_connect(). If unset,
288288
; mysql_connect() will use the $MYSQL_TCP_PORT, or the mysql-tcp
289289
; entry in /etc/services, or the compile-time defined MYSQL_PORT
290290
; (in that order). Win32 will only look at MYSQL_PORT.
291+
mysql.default_socket = ; default socket name for local MySQL connects. If empty, uses the built-in
292+
; MySQL defaults
291293
mysql.default_host = ; default host for mysql_connect() (doesn't apply in safe mode)
292294
mysql.default_user = ; default user for mysql_connect() (doesn't apply in safe mode)
293295
mysql.default_password = ; default password for mysql_connect() (doesn't apply in safe mode)

0 commit comments

Comments
 (0)