Mantis - Quercus
Viewing Issue Advanced Details
5174 minor always 08-07-12 16:23 08-08-12 06:15
new 4.0.28  
0005174: Quercus cannot find or include PHP files through WAR overlay

I am using Jetty to run the Quercus webapp (WAR file). I do this using the jetty-maven-plugin and the jetty:run Maven goal. The jetty:run goal does some handy things with overlaying WAR files, and allows me to edit .php files while the web server is running. In other words, I can edit my PHP webapp and see changes in real time.

At one point I had the idea of separating some of the PHP files into a separate WAR file for maintainability (e.g. a PHP framework or CMS) and overlay that WAR over my webapp project. This gives me some troubles however, as Quercus is unable to locate the .php files from the overlaid WAR when Jetty is started using the jetty:run Maven goal. It does work correctly when using the jetty:run-war goal, but, then I cannot edit my PHP files and directly see the changes (I have to stop the web server and start it again).

I have been digging around somewhat, and I think this might be related to a servletContext.getRealPath() call that is missing somewhere in the Quercus code (instead another mechanism is used to determine the requested script location). This suspicion is getting stronger when looking at file modules/quercus/src/com/caucho/quercus/servlet/, line 287:

  protected Path getPath(HttpServletRequest req)

(full method source code under "Additional Information") This method has req.getRealPath() explicitly commented out because of an earlier incompatibility (php/8173, I can't find anything about it unfortunately). But, this causes a new incompatibility with WAR overlays, because WAR overlays rely on getRealPath().

I am thinking about how to fix this. I could use some pointers on how to go about this. For example, if I fix it here, will it also work for php include/require calls? Also, if possible, I would also like some background information on issue php/8173 to make sure I don't recreate the former issue.

Any feedback is greatly appreciated.
The full getPath() method from modules/quercus/src/com/caucho/quercus/servlet/ for reference:

  protected Path getPath(HttpServletRequest req)
    // php/8173
    Path pwd = getQuercus().getPwd().copy();

    StringBuilder sb = new StringBuilder();
    String servletPath = QuercusRequestAdapter.getPageServletPath(req);

    if (servletPath.startsWith("/")) {
      sb.append(servletPath, 1, servletPath.length());
    else {

    String pathInfo = QuercusRequestAdapter.getPagePathInfo(req);

    if (pathInfo != null) {

    String scriptPath = sb.toString();

    Path path = pwd.lookupChild(scriptPath);

    return path;

    /* jetty getRealPath() de-references symlinks, which causes problems with MergePath
    // php/8173
    Path pwd = getQuercus().getPwd().copy();

    String scriptPath = QuercusRequestAdapter.getPageServletPath(req);
    String pathInfo = QuercusRequestAdapter.getPagePathInfo(req);

    Path path = pwd.lookup(req.getRealPath(scriptPath));

    if (path.isFile())
      return path;

    // XXX: include

    String fullPath;
    if (pathInfo != null)
      fullPath = scriptPath + pathInfo;
      fullPath = scriptPath;

    return pwd.lookup(req.getRealPath(fullPath));

08-08-12 06:15   
I can confirm that restoring the commented out code in the getPath() method fixes the overlay problem (tested against quercus 4.0.29). However, include/require calls seem to fail (not surprisingly as there is a XXX for this in the commented out code). Because include/require calls fail, there is not a good solution yet. I will keep on working on this, but my experience with the quercus code base is quite minimal so far :-)