0

I'm using google app engine locally and the request returns what it should.

Then I try on google app engine (the appspot service myapp.appspot.com) and the exact same call simply returns false without any errors.

The php documentation says I should get an error or a warning but I really don't see anything. http://www.php.net/manual/en/function.file-get-contents.php

I found this gae php documentation below but I really can't figure out what could be wrong. https://developers.google.com/appengine/docs/php/urlfetch/

I'm trying to fetch an url of another app from the appspot and the gae doc says:

Making requests to another App Engine app

If you are making requests to another App Engine app, you should consider telling the URL Fetch service to not follow redirects when invoking it.

Does anyone know how do I do that, or maybe what could even be the real problem ?

Here is my snippet:

    $content = file_get_contents($url, 0, $context);
    if (false === $content) {
        $error = error_get_last();
        throw new ClientException($error['message']);
    }

UPDATE:

Here is my php.ini:

google_app_engine.enable_functions = "php_sapi_name, php_uname, getmypid"
google_app_engine.allow_include_gs_buckets = "storage_bucket_name"
allow_url_include=1
allow_url_fopen=1

I tried with the following code:

    error_reporting(-1);
    ini_set('display_errors', 1);
    $content = file_get_contents($url, 0, $context);
    if (false === $content) {
        $error = error_get_last();
        throw new ClientException($error['message']);
    }

Now I get this error: "failed to open stream: Invalid headers. Must be a string."

This is my $context variable which is passed through stream_context_create(): http://www.php.net/manual/fr/function.stream-context-create.php

array(2) {
  ["http"]=>
  array(7) {
    ["method"]=>
    string(3) "GET"
    ["header"]=>
    string(0) ""
    ["content"]=>
    NULL
    ["protocol_version"]=>
    float(1)
    ["ignore_errors"]=>
    bool(true)
    ["max_redirects"]=>
    int(5)
    ["timeout"]=>
    int(5)
  }
  ["ssl"]=>
  array(1) {
    ["verify_peer"]=>
    bool(true)
  }
}

This is leading me to that old thread:

Using file_get_contents invalid headers issue on GAE

Community
  • 1
  • 1
user1855153
  • 579
  • 4
  • 15

1 Answers1

1

Since I had the error "failed to open stream: Invalid headers. Must be a string." I focused on the header part of the context.

The $context['http']['headers'] was obviously a string(0) ""

I tried to unset the $context['http']['headers'] if it was empty and the problem is solved.

Note: this happens only in Google App Engine (GAE)

user1855153
  • 579
  • 4
  • 15