0

All other static files are serving as normal at domain.

It seems PHP file wasn't running; when I don't try to run it as a script (and just upload it as a static file) it works fine; returning plaintext when jQuery calls it - so its definitely not a file path problem.

But once I list it as a php file in yaml and expect the jQuery to GET 'hello, world!' it returns 404 in the Firefox network monitor and there's a no response in the console.

Is there something I'm missing with regard to running a solitary server-side php script on App Engine Standard?

app.yaml

runtime: php55
api_version: 1
threadsafe: true

handlers:
# Serve php scripts another way.
- url: /scripts/elastic.php
  script: scripts/elastic.php

# Handle the main page by serving the index page.
# Note the $ to specify the end of the path, since app.yaml does prefix matching.
- url: /$
  static_files: index.html
  upload: index.html


# Handle folder urls by serving the index.html page inside.
- url: /(.*)/$
  static_files: \1/index.html
  upload: .*/index.html

# Handle nearly every other file by just serving it.
- url: /(.+)
  static_files: \1
  upload: (.*)

elastic.php

<?php
return 'Hello, world!'
?>

script.js (called after jQuery loads in my index.html)

$(document).ready(function(){
    $.get("./scripts/elastic.php", function( data ) {
      console.log(data);
    });
});
Diz
  • 61
  • 1
  • 7

1 Answers1

1

What I think is happening is that your final handlers directive is telling the deployment to treat all files in your application as uploadable and static. I believe this is resulting in your calls to the earlier script being mishandled (maybe an App Engine bug...).

If you change your final handler to be either a PHP script or something like the following then you should be mostly good:

- url: /(.*)
  static_files: \1
  upload: (.*)\.html

You'll also want to have your PHP script echo or print results in the response rather than return, which doesn't actually return anything to the browser for display.

BrettJ
  • 6,801
  • 1
  • 23
  • 26
  • You're 100% correct! For some reason I thought it cascaded such that the initial script handler had caught all php files before they could get further down the funnel. I adjusted the title so your answer can help more people. Thanks Brett :) – Diz Oct 25 '17 at 09:50
  • It is supposed to operate that way for at least the URL matching, but I think during the upload process the file is getting overwritten or reclassified as static. I will open a bug about the behavior and see what comes of that. Might just be that we need to warn people in the docs that this can happen. – BrettJ Oct 25 '17 at 16:39