Perforce Public Knowledge Base - Building P4PHP on Windows
× PRODUCTS SOLUTIONS CUSTOMERS LEARN SUPPORT
Downloads Company Partners Careers Contact Free Trials
Menu Search
Perforce
Reset Search
 

 

Article

Building P4PHP on Windows

« Go Back

Information

 
Problem

How do I build the P4PHP API on Windows?

Solution

This article provides further detail for the steps listed in the P4PHP release notes.

Note: In order to create a P4PHP binary for Windows, you will need to set up a complete PHP build environment to build the P4PHP DLL.

Setting up a PHP Build Environment

To setup a proper build environment for PHP, please refer to the instructions on the PHP wiki.  Note that at this time P4PHP will only build properly with Visual Studio 2008 (VC9), as that is the version that most versions (including the official versions) of PHP and Apache are built with.  You will also need the Windows SDK 6.  The latest version (SDK 7) includes the 2010 visual studio compiler (VC10), and should be avoided.

 

While it's theoretically possible to compile P4PHP with VS 2010 and the Windows 7.1 SDK, it is unsupported.

 

 Note that p4php does not currently build against php 5.4, however 5.3 is supported.

Building P4PHP 

Once a Windows build environment capable of building PHP is configured, you can build the P4PHP extension. We will build P4PHP as a DLL that can be added to the PHP installation.

Requirements
 

  • The headers and library files for the version of OpenSSL that the P4API library was built with.  To find out what version of OpenSSL is required, you can use the 'strings' command (available from the Gnuwin32 utilities for Windows) to find out:
     
  • C:\p4api\p4api-2012.1.442152-vs2010_dyn_vsdebug\lib>strings librpc.lib | grep OpenSSL
    ??_C@_0BL@KMNDIDNM@OpenSSL?51?40?40g?518?5Jan?52012?$AA@
    ??_C@_0BM@HBIBNIPC@OpenSSL?5compile?5version?5?$CFs?6?$AA@
    ??_C@_0BM@LKACEJKK@OpenSSL?5runtime?5version?5?$CFs?6?$AA@
    ??_C@_0BL@KMNDIDNM@OpenSSL?51?40?40g?518?5Jan?52012?$AA@
    ??_C@_0BM@HBIBNIPC@OpenSSL?5compile?5version?5?$CFs?6?$AA@
    ??_C@_0BM@LKACEJKK@OpenSSL?5runtime?5version?5?$CFs?6?$AA@
    OpenSSL 1.0.0g 18 Jan 2012 <-- Version of OpenSSL
    OpenSSL compile version %s
    OpenSSL runtime version %s
    Version mismatch between compile OpenSSL version and runtime OpenSSL version.
    ??_C@_0BL@KMNDIDNM@OpenSSL?51?40?40g?518?5Jan?52012?$AA@
    ??_C@_0BM@HBIBNIPC@OpenSSL?5compile?5version?5?$CFs?6?$AA@
    ??_C@_0BM@LKACEJKK@OpenSSL?5runtime?5version?5?$CFs?6?$AA@
    

    You can see from this that the version used is 1.0.0g. You can download the libraries from OpenSSL.org, or compile them directly from source. (Easy, you already have all the tools you need). Copy the header files, binaries and libs to the PHP deps path (if you followed the default PHP instructions, this will be C:\php-sdk\php53dev\vc9\x86\deps\ - copy the headers into include, the libs into lib, and the binaries into bin.)

 

    Procedure

    1. Extract P4PHP to the directory:

      C:\php-sdk\php53dev\vc9\x86\php-{version}\ext\

      You will get a path like:

      C:\php-sdk\php53dev\vc9\x86\php-{version}\ext\p4php-{version}\
    2. Rename  p4php-{version} directory to p4_php.

      Note: The directory is named p4_php (with an underscore), not p4-php (hyphen). This is because p4-php is a build macro variable, so using this as a directory name will break the build.

    3. In the SDK shell, switch to the directory:

      cd C:\php-sdk\php53dev\vc9\x86\php-{version}
      Reset the configuration by entering the command:
      buildconf
    4. Configure with the following options:

       

      configure --disable-all --enable-cli --with-perforce=<path to p4api>,shared
      

       

    5. Run nmake by entering:

      nmake

      The php_perforce.dll will be created in the Release_TS directory.

    To test it, you can copy the DLL into the ext directory of an existing PHP installation.

    Note: This version of PHP must be the same version as the one you compiled P4PHP with.

    To enable PHP to actually use the dll, you need to either run php from the command line with the option:

    php.exe -d extension=php_perforce.dll

    Or you can specify it in the php.ini file of the php distribution. See Installation, below.

    Installation

    Once you have built PHP/P4PHP, you will need to install it. This involves three steps:

    1. Copy the PHP release tree (The Release_TS directory) to C:\PHP5. This is the recommended location. It can be placed elsewhere, but then you will need to edit the php.ini file so that it can find its extensions. You can also copy the php_perforce.dll to an existing PHP installation provided it's the same version of PHP.
     
    C:\Windows\system32>copy C:\php-sdk\php53dev\vc9\x86\php-<ver>\php.ini-production C:\Windows\php.ini
            1 file(s) copied.
    

    Edit the php.ini file and add the line:

    extension=php_perforce.dll

    Note: You can skip this step if not planning on doing anything other than testing P4PHP. Creating/Editing a php.ini file is outside the scope of this document. Just use this command when loading your test scripts:

    php -d extension=<path_to>\php_perforce.dll .

    Testing P4PHP

    Performing quick tests of P4PHP.

    Note: The Windows version of PHP does not support interactive mode, so you will need to write up a script and then run it.

    To confirm that PHP is in the PATH and that the php_perforce.dll is being loaded, enter:

    php -V
    

    This will produce output similar to:

    Usage: php [options] [-f] <file> [--] [args...]
           php [options] -r <code> [--] [args...]
           php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
           php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
           php [options] -- [args...]
           php [options] -a
    
      -a               Run interactively
      -c <path>|<file> Look for php.ini file in this directory
      -n               No php.ini file will be used
      -d foo[=bar]     Define INI entry foo with value 'bar'
      -e               Generate extended information for debugger/profiler
      -f <file>        Parse and execute <file>.
      -h               This help
      -i               PHP information
      -l               Syntax check only (lint)
      -m               Show compiled in modules
      -r <code>        Run PHP <code> without using script tags -B <begin_code> Run PHP <begin_code> before processing input lines
      -R <code>        Run PHP <code> for every input line
      -F <file>        Parse and execute <file> for every input line
      -E <end_code>    Run PHP <end_code> after processing all input lines
      -H               Hide any passed arguments from external tools.
      -s               Output HTML syntax highlighted source.
      -v               Version number
      -w               Output source with stripped comments and whitespace.
      -z <file>        Load Zend extension <file>.
    
      args...          Arguments passed to script. Use -- args when first argument
                       starts with - or script is read from stdin
    
      --ini            Show configuration file names
    
      --rf <name>      Show information about function <name>.
      --rc <name>      Show information about class <name>.
      --re <name>      Show information about extension <name>.
      --ri <name>      Show configuration for extension <name>.

    To check the loaded modules, enter:

    php -m

    This produces a list of the currently loaded PHP modules, similar to:

    [PHP Modules]
    Core
    date
    ereg
    pcre
    PDO
    perforce
    Reflection
    SPL
    standard
    
    [Zend Modules]
    

    If you see perforce listed in the modules then the php_perforce.dll is being loaded properly. Proceed to testing.

    Place the following in a file named p4php_info.php.

    <?php
    $p4 = new P4();
    print_r($p4->identify());
    $p4->port = 'localhost:1666';
    $p4->user = 'bruno';
    $p4->connect();
    print_r($p4->run('info'));
    $p4->disconnect();
    ?>
    

    Now run p4php_info.php:

    php -f p4php_info.php

    The output will be similar to:

    Perforce - The Fast Software Configuration Management System.
    Copyright 1995-2010 Perforce Software.  All rights reserved.
    Rev. P4PHP/NTX86/2009.2/239532 (2009.2 API) (2010/03/24).
    Array
    (
        [0] => Array
            (
                [userName] => bruno            [password] => enabled
                [clientName] => test-ws
                [clientRoot] => c:\Users\bruno\Documents\local
                [clientCwd] => C:\Users\bruno\Documents\local
                [clientHost] => tombstone
                [clientAddress] => 192.0.0.1:1666            [serverName] => Bruno P4D
                [serverDescription] => Bruno test service
                [monitor] => enabled
                [security] => enabled
    
                [serverAddress] => Bruno:1666
                [serverRoot] => C:\Program Files\Perforce\Server
                [serverDate] => 2010/03/29 15:09:00 -0700 Pacific Daylight Time
                [serverUptime] => 102:44:51
                [serverVersion] => P4D/NTX64/2009.2/228098 (2009/12/16)
                [serverLicense] => none
            )
    
    )
    

    Using P4PHP with IIS

    Running php on Windows through IIS requires a non thread safe (NTS) php build. The instructions in the above build a thread safe (TS) php_perforce.dll. NTS PHP can't run a TS php_perforce.dll.

    • Create a php.ini file in the C:\Windows directory, or copy (as Administrator) one of the php.ini files in the PHP source tree to C:\Windows\php.ini. For example:
    • Add the C:\PHP5 directory to the PATH variable by selecting Start Menu | Control Panel | System | Advanced Settings | Environment Variables.

      Note: You can ignore this step if you are placing php_perforce.dll in an existing installation.
    Here's how to configure NTS versions of php and the php_perforce.dll:
    configure --disable-all --enable-cli --disable-zts
    
    
    configure --disable-all --enable-cli --disable-zts --with-perforce=<path to p4api>,shared
    Related Links

    Feedback

     

    Was this article helpful?


       

    Feedback

    Please tell us how we can make this article more useful.

    Characters Remaining: 255