0

Firstly, I'm using Windows (XP -- yes, I know), php-fpm (5.4.9) and nginx (1.5.10). My local development environment is functioning well.

I use the .dev extension for local domain names to point to local website projects. For example: example.dev or www.example.dev.

I've setup my hosts file (C:\Windows\System32\drivers\etc\hosts) to contain these additional records: 127.0.0.1 example.dev www.example.dev

When I ping them the domain name www.example.dev it resolves to 127.0.0.1 as you would expect.

I can visit the page: http://www.example.dev in my browser and it displays some 'Hello World' text as you would expect to see.

Now if I run the following script in a browser, it does not work:

<?php var_dump( file_get_contents( 'http://www.example.dev' ) ); ?>

For me nginx just times-out, even though I can navigate to it in my browser without issue.

Now for cURL, the follow doesn't work either:

<?php

    $url = 'http://www.example.dev';

    $ch = curl_init();

    $options = array(
        'CURLOPT_URL'             => $url,
        'CURLOPT_HEADER'          => TRUE,
        'CURLOPT_FAILONERROR'     => FALSE,
        'CURLOPT_FOLLOWLOCATION'  => TRUE,
        'CURLOPT_AUTOREFERER'     => TRUE,
        'CURLOPT_RETURNTRANSFER'  => TRUE,
        'CURLOPT_FRESH_CONNECT'   => TRUE,
    );

    foreach ( $options as $k => $v )
    {
        curl_setopt( $ch, constant( $k ), $v );
    };

    $response    = curl_exec( $ch );
    $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE );
    $status_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
    $info        = curl_getinfo( $ch );

    curl_close( $ch );

    var_dump( $response ); exit;
?>

However if I replace example.dev with localhost, these code samples do appear to work.

paperclip
  • 2,280
  • 6
  • 28
  • 39

1 Answers1

0

This appears to be related to the fact that PHP-FPM doesn't actually work on Windows. See https://stackoverflow.com/a/10640722/156406

The easiest way around this is to spawn your own pool of PHP instances using a .bat file and use nginx to send requests to the pool.

Create the following php-pool.bat updating all the references for your particular install.

@ECHO Off
SETLOCAL EnableDelayedExpansion
SET phpdir=C:\Server\php\5.4.9
SET phpnum=3

REM Kill currently running PHP Processes.
TASKKILL /f /IM php-cgi.exe

FOR /L %%G IN (0, 1, %phpnum%) DO (
    REM ECHO Starting PHP Instance: %phpsrv%:900%%G
    START /b %phpdir%\php-cgi.exe -b 127.0.0.1:900%%G: -c %phpdir%\php.ini
)

Then update your nginx configuration file:

upstream backend {
    server 127.0.0.1:9000 weight=1;
    server 127.0.0.1:9001 weight=1;
    server 127.0.0.1:9002 weight=1;
}

server {
    ...
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass backend;
        fastcgi_index index.php;
        include fastcgi_params;
    }
    ...
}

This isn't a perfect solution but gets the examples working for me. See more here: https://bitbucket.org/cybergene/spawn-php/wiki/Home

Community
  • 1
  • 1
paperclip
  • 2,280
  • 6
  • 28
  • 39