From: <php...@li...> - 2018-02-11 14:23:16
|
Hi, I have a Apache/PHP front end and a tomcat back end. There ~50 PHP processes in the pool and each of it has a persistent connection to a Java thread running from the PHP/Java Bridge. I've noticed that each time a php/java script is executed, the bridge sends a PUT request to tomcat, even though the php process has a persistent connection to a java thread. I think this PUT request is unnecessary, unless a PHP process doesn't have persistent connection yet or it needs to get a session handle from the back end. The following patch adds an attribute "allocateJavaSession" to class java_Client. It is set if java_session() is called. If the bridge needs to connect to the back end, it knows if it needs to allocate a session. If no session is requested, it can check if a persistent connection to 9267 exists and can be re-used. If so, it re-directs to the persistent connection using some fake JAVABRIDGE_CONTEXT. (My understanding is that the context is only useful while re-directing from the servlet to the java thread). So in the regular case no socket connect is necessary anymore. PHP can send data right away and receive the results using the connection it already has: function java_session_array($args) { $client=__javaproxy_Client_getClient(); + $client->allocateJavaSession=true; if(!isset($args[0])) $args[0]=null; ... $this->serverName="${ssl}${host}:$port"; + if (!$this->client->allocateJavaSession) { + $errno=null; $errstr=null; + $sock=@pfsockopen($host,"9267",$errno,$errstr,5); + if ($sock && !$errno && ftell($sock)>0) { + $_SERVER['X_JAVABRIDGE_REDIRECT']="9267"; + $_SERVER['X_JAVABRIDGE_CONTEXT']="9267|".microtime(); + } +} The above patch should give a performance boost for all php scripts which don't care about a java_session(), while stay compatible with scripts which need a session. Peter |