📜 ⬆️ ⬇️

Host and Request_Uri in the list of Oracle sessions

In order to see the request from the web in the list of sessions on the Oracle server, it is enough to add 7 lines of code to the PHP OCI8 extension.




')
File

ext/oci8/oci8.c 


At the beginning

 #include "SAPI.h" 


In the function php_oci_do_connect insert six lines

  if (!connection) { RETURN_FALSE; } char* hostname = sapi_getenv("HTTP_HOST", 100 TSRMLS_CC); char* uri = sapi_getenv("REQUEST_URI", 100 TSRMLS_CC); char* reqid = sapi_getenv("HTTP_X_REQUEST_ID", 32 TSRMLS_CC); PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) hostname, (ub4) strlen(hostname), (ub4) OCI_ATTR_MODULE, OCI_G(err))); PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) uri, (ub4) strlen(uri), (ub4) OCI_ATTR_ACTION, OCI_G(err))); PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) reqid, (ub4) strlen(reqid), (ub4) OCI_ATTR_CLIENT_INFO, OCI_G(err))); RETURN_RESOURCE(connection->rsrc_id); 


Module and action are visible not only in V $ SESSION, but also in V $ SQLAREA. In addition to host and request_uri, we are writing a unique pass-through request identifier, which can then be tracked by the nginx and apache logs.

Source: https://habr.com/ru/post/150542/


All Articles