0

The below http-request issued from an Zend Controller Action towards localhost fails with a timeout. My guess is that I have missed a very basic concept, since a request to an outside uri (e.g. www.google.com) returns normally.

Of course the URL below ($localUrl) does return the expected result (TEST) when pasted directly into the browser.

I am using Zend Framework 2 (based on the current skelleton application - today: 2016/06/19) in an XAMPP 3.2.2 Windows (Developer Environment) with PHP 5.6.21 and xdebug enabled.

update 1

I've debugged a bit deeper now:

When the request is sent, the programm is stuck for the duration of the timeout.

After that I get a "Zend\Http\Client\Adapter\Exception\TimeoutException".

Following that the code inside the debugger jumps into the php script requested (checklogin.php) which I have filled with with just an echo statement for simplicity.

After that, instead of continuing returning the result in the Action function the script stops and I get presented with the Timeout Exception Errorpage.

Please do not read too much into the code for now, since it does not properly handle the result yet.

namespace MyModule\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Http\Client;

class PhpbbAuthController extends AbstractActionController{

public function checkAction(){
    $localUrl = 'http://localhost/zendproject/public/phpbbauth/checklogin.php';

    $client = new Client($localUrl , array(
      'maxredirects' => 0,
      'timeout'      => 10
    ));
    $response = $client->send();

    return new ViewModel(array('content'=>$response->getContent()));
}

}

update 2

Content of checklogin.php

<?php
echo "TEST";
?>

Small Note: There are very likely far better sollutions for my overall problem, which is integrating a zend application into the PHPBB3 Authentication of an existing Forum, but including this here would go beyond the scope of this question.

elfwyn
  • 568
  • 2
  • 11
  • 33
  • Why do you choose to handle the login check outside the application in a separate file? Maybe you can share the contents of this file? – Wilt Jun 19 '16 at 13:13
  • The script called would include the PHPBB3 base script and run the session_begin() to initialize the global $user object. Afterwards it would return the State as Json. Currently it just calls echo. There are of course other scripts to login or logout. Ive tried to use that code directly inside the Controller, but i've had multiple problems there since the initialization of PHPBB does not run as expected in the Zend environment. (e.g. global $request is null) Since the overarcing project does not have a direct bearing on the problem at hand I decided to leave those questions for another day. – elfwyn Jun 19 '16 at 14:05
  • Is the file accessible on that path? So when you open the url `http://localhost/zendproject/public/phpbbauth/checklogin.php`in your browser it outputs `TEST`? Should it not be: `http://localhost/phpbbauth/checklogin.php`? – Wilt Jun 19 '16 at 14:19
  • When pasting exactly that url into my browser "TEST" ist displayed correctly. This is due to the fact that I did not customize my Apache configuration for the dev/test environment, so it still defaults to "htdocs". Furthermore I have multiple Zend 2 Skelletons in htdocs (of which "zendproject" is one), leading to this structure. – elfwyn Jun 19 '16 at 14:34
  • I was hoping maybe that this is an Apache problem I am not familiar with or that there is some restriction on requesting php files on the same server from a running php during the same request. I also checked potential Firewall issues and found nothing. – elfwyn Jun 19 '16 at 14:40
  • Well, if you can't even open the file in your browser then I guess there is your issue. Try to solve that and the code above will also work... – Wilt Jun 19 '16 at 14:52
  • Sorry for the misunderstanding - maybe it's because I am no native speaker. "This url" mentioned in the previous comment is "$localUrl" and I have tested the url more than once even with various host representations (localhost,127.0.0.1,). The Url is good. Sorry again for my poor choice of wording. – elfwyn Jun 19 '16 at 15:18

0 Answers0