3

I have been trying to use PHP on Tomcat (don't ask why, I just have to), and have been following the Configure PHP with Tomcat and several tutorials given for PHP with PECL & Tomcat.

I've done most of the things required by the tutorials, like setting all the environment variables that are required, but I still run into errors such as the one shown below, on startup:

javax.servlet.ServletException: Servlet.init() for servlet php threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    java.lang.Thread.run(Thread.java:619)

root cause

java.lang.UnsatisfiedLinkError: C:\WINDOWS\system32\php5servlet.dll: The specified procedure could not be found
    java.lang.ClassLoader$NativeLibrary.load(Native Method)
    java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
    java.lang.ClassLoader.loadLibrary(ClassLoader.java:1728)
    java.lang.Runtime.loadLibrary0(Runtime.java:823)
    java.lang.System.loadLibrary(System.java:1028)
    net.php.reflect.loadLibrary(reflect.java:34)
    net.php.reflect.<clinit>(reflect.java:29)
    net.php.servlet.init(servlet.java:157)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    java.lang.Thread.run(Thread.java:619)

Also, whenever I refresh a page. It gives this exception :

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.UnsatisfiedLinkError: 
net.php.servlet.send(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Z)V
net.php.servlet.send(Native Method)
net.php.servlet.service(servlet.java:190)
net.php.servlet.service(servlet.java:214)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

I have been trying to solve this, unsuccessfully, since yesterday. Can anyone tell me what am I doing wrong here? Or what the solution might be? Thanks.

4

1 回答 1

1

What version of PHP are you using?

Not all versions of PHP supports php5servlet. The php5servlet.dll library needs a function or method contained in the library php5ts.dll, but this library php5ts.dll changes according to version of PHP (adding new or substracting old methods), for this reason when php5servlet.dll calls some method, maybe can't found it.

You need one version of PHP (maybe older than you are using) according to PECL Library that you are using.

The last tested version of PHP for me is http://windows.php.net/downloads/releases/archives/php-5.2.16-Win32-VC6-x86.zip

I do not know still why PHP 5.3.0 or newer VC6 is not functional.

The last version of PECL with the required library (php5servlet.dll, php_java.dll, php_java.jar and phpsrvlt.jar) was http://museum.php.net/php5/pecl-5.2.5-Win32.zip

The Tomcat used for this testing was http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.27/bin/apache-tomcat-7.0.27-windows-x86.zip

If you want to work only with .php files...

Now (This below part is not the reason for the error, so do not fix it.), you can work putting your .php files directly in

TOMCATDIR\webapps\ROOT\

putting the generated .jar file php5srvlt.jar inside of \lib obviously changing the web.xml file to something like:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"
  metadata-complete="true">
  <servlet>
    <servlet-name>php</servlet-name>
    <servlet-class>net.php.servlet</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>php-formatter</servlet-name>
    <servlet-class>net.php.formatter</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>php</servlet-name>
    <url-pattern>*.php</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>php-formatter</servlet-name>
    <url-pattern>*.phps</url-pattern>
  </servlet-mapping>
</web-app>
于 2013-10-18T04:21:00.877 回答