PHP_METHOD(swoole_http_server, on) { zval *callback; zval *event_name; swServer *serv; if (SwooleGS->start > 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Server is running. Unable to set event callback now."); RETURN_FALSE; } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &event_name, &callback) == FAILURE) { return; } SWOOLE_GET_SERVER(getThis(), serv); char *func_name = NULL; if (!zend_is_callable(callback, 0, &func_name TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Function '%s' is not callable", func_name); efree(func_name); RETURN_FALSE; } efree(func_name); if (strncasecmp("request", Z_STRVAL_P(event_name), Z_STRLEN_P(event_name)) == 0) { zval_add_ref(&callback); php_sw_http_server_callbacks[0] = callback; } else if (strncasecmp("message", Z_STRVAL_P(event_name), Z_STRLEN_P(event_name)) == 0) { zval_add_ref(&callback); php_sw_http_server_callbacks[1] = callback; } else if (strncasecmp("handshake", Z_STRVAL_P(event_name), Z_STRLEN_P(event_name)) == 0) { zval_add_ref(&callback); php_sw_http_server_callbacks[2] = callback; } else if (strncasecmp("open", Z_STRVAL_P(event_name), Z_STRLEN_P(event_name)) == 0) { zval_add_ref(&callback); php_sw_http_server_callbacks[3] = callback; } else { zend_call_method_with_2_params(&getThis(), swoole_server_class_entry_ptr, NULL, "on", &return_value, event_name, callback); } }
PHP_METHOD(swoole_http_server, on) { zval *callback; char *event_name; swServer *serv; int len; if (SwooleGS->start > 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Server is running. Unable to set event callback now."); RETURN_FALSE; } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &event_name, &len, &callback) == FAILURE) { return; } SWOOLE_GET_SERVER(getThis(), serv); char *func_name = NULL; if (!zend_is_callable(callback, 0, &func_name TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Function '%s' is not callable", func_name); efree(func_name); RETURN_FALSE; } efree(func_name); if (strncasecmp("request", event_name, len) == 0) { zval_add_ref(&callback); php_sw_http_server_callbacks[0] = callback; } else if (strncasecmp("message", event_name, len) == 0) { zval_add_ref(&callback); php_sw_http_server_callbacks[1] = callback; } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unknown event types[%s]", event_name); RETURN_FALSE; } }