Reputation: 45
I'm trying to migrate a PHP application to Google App Engine infrastructure and I have a similar piece of code that handle sessions:
<html>
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
</head>
<body>
<?php
session_start();
?>
</body>
</html>
When executing it with GAE SDK I get the following errors and the sessions do not keep track of the records I have previously set:
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Users\user\Downloads\google_appengine_1.8.1\google_appengine\php\sdk\google\appengine\runtime\RemoteApiProxy.php on line 92 Warning: file_get_contents(http://localhost:63143): failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Users\user\Downloads\google_appengine_1.8.1\google_appengine\php\sdk\google\appengine\runtime\RemoteApiProxy.php on line 92 Notice: Undefined offset: 0 in C:\Users\user\Downloads\google_appengine_1.8.1\google_appengine\php\sdk\google\appengine\runtime\Memcache.php on line 564
I have set the following values in php.ini
file:
session.save_handler = user
session.save_path = Memcache
Does anybody know if there is some missing configuration I need to set in order to use sessions?
EDIT:
I removed the php.ini
file from the project folder and some errors still occur, there are 2 different warnings that haven't appeared the last time:
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Users\user\Downloads\google_appengine_1.8.1\google_appengine\php\sdk\google\appengine\runtime\RemoteApiProxy.php on line 92 Warning: file_get_contents(http://localhost:50074): failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Users\user\Downloads\google_appengine_1.8.1\google_appengine\php\sdk\google\appengine\runtime\RemoteApiProxy.php on line 92 Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Users\user\Downloads\google_appengine_1.8.1\helloworld\helloworld.php:7) in C:\Users\user\Downloads\google_appengine_1.8.1\helloworld\helloworld.php on line 8 Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Users\user\Downloads\google_appengine_1.8.1\helloworld\helloworld.php:7) in C:\Users\user\Downloads\google_appengine_1.8.1\helloworld\helloworld.php on line 8
I'm running on Windows 7 Enterprise x64, php-5.4.13-Win32-VC9-x86 and google_appengine_1.8.1.
Upvotes: 2
Views: 4388
Reputation: 81
Session in GAE PHP are automatically stored in memcache, you don't need to configure anything.
was very misleading to me. It may worked back then. Nowadays, each PHP instance has it's own PHP session management by default. If you like centralized PHP session management stored in Google GAE memcache, you have to configure it!
A working possible legacy solution:
Upvotes: 0
Reputation: 71
Actually, the error is because you should start by the session.
session_start() has to be the first thing in your code.
Try this:
<?php
session_start();
?>
<html>
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
</head>
<body>
</body>
</html>
Upvotes: 0
Reputation: 344
I also had issues with the php session_start() function when deploying my application using Google App Engine; I had the following warnings:
Warning: session_start(): Cannot send session cookie - headers already sent by...
Warning: session_start(): Cannot send session cache limiter - headers already sent...
I finally came to understand that Google App Engine automatically creates a session, so you don't need to create one yourself.
Just go ahead and keep whatever you want in a session variable, and try to retrieve it somewhere else. You will not have any error.
The thing to remember here is that you don't need to start a session yourself using session_start(), one has already been started by Google App Engine, so you just use it.
Upvotes: 0
Reputation: 1062
If someone EVER hits on this page again, but solutions here aren't working, but get the "Headers already sent" error:
Try saving as UTF-8 without BOM. this is usually a White space error, and BOM is usually read as a character which is outputted before anything could happen.
Upvotes: 0
Reputation: 2001
It looks like you may have found a bug. Specifically it looks like by setting your session handler in PHP.ini the PHP interpreter is attempting to access a memcached server directly via the network rather than the implementation provided by the dev_appserver.
Would you mind reporting it at: https://code.google.com/p/googleappengine/issues/list?q=label:Language-PHP&sort=-stars
Additionally, Google App Engine actually uses Memcache for sessions by default as described in https://developers.google.com/appengine/docs/php/#Sessions without any custom configuration.
Upvotes: 0
Reputation: 7054
Session in GAE PHP are automatically stored in memcache, you don't need to configure anything.
Can you remove your php.ini file and see if the problem persists?
Upvotes: 0