Installing P4 API for PHP
Depending on if you are using a Windows, macOS or Linux machine determines how to install P4 API for PHP
Installing P4 API for PHP on Windows
To install P4 API for PHP on Windows, follow these steps:
Download the relevant files and apps
To build the P4 API for PHP, download the following:
PHP
Download the latest stable version of PHP 8.4 from the PHP website:
-
Select a Thread Safe version.
-
Select x64 (64-bit) and the latest stable version (currently 8.4).
-
Download the ZIP file (not the installer).
P4 API for PHP
You will also need the P4PHP extension, this is a .dll file.
-
Download this extension can from the Perforce archive.
-
This file must match:
-
The version of PHP you have (for example 8.4).
-
Either Thread Safe or not.
-
-
For example, download
perforce_php84ts.dllfor PHP 8.4 TS (Thread Safe).
Configure P4 API for PHP
When you have all the required files and apps, follow these steps:
-
Go to the directory that contains PHP.
-
Copy the perforce
.dllfile into the PHPextfolder. For example, the file path for this.dllfile would be:C:\php\ext\perforce_php84ts.dll -
In the PHP directory, find and open the
php.inifile, and add the following line to the bottom of the file:extension=perforce_php84ts.dll -
Save
php.ini -
Verify the
.dllfile has loaded. In the command prompt, navigate to the PHP directory and run the following:php -m -
You should see
perforcelisted in the modules in the output.
(Optional) Test the P4 API for PHP installation
To test the test the P4 API for PHP installation, follow these steps:
-
Create a folder for testing, for example:
C:\p4test) -
In this folder, create a test file, for example,
test_p4.php. -
Enter the following into
test_p4.php:Copy<?php
error_reporting(E_ALL & ~E_DEPRECATED); // hide deprecated warnings
try {
// Create a new P4 connection
$p4 = new P4();
// Set server, user, and workspace
$p4->Port = 'perforce:1666'; // Replace with your server
$p4->User = 'your-username'; // Replace with your username
$p4->Client = 'your-workspace'; // Replace with your workspace
// Connect
$p4->Connect();
echo "Connected to Perforce successfully!\n";
// Disconnect
$p4->Disconnect();
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}Make sure you update thePort,UserandClientfields. -
Open the command prompt and navigate to your test folder:
cd C:\p4test -
Run the script:
php test_p4.php -
If the test is successful, you will see the following output:
Connected to Perforce successfully!
Installing P4 API for PHP on macOS or Linux
To install P4 API for PHP on macOS or Linux, follow these steps:
Download the relevant files and apps
To build P4 API for PHP, you’ll need the following PHP files:
-
The PHP header files and libraries.
-
The
phpizecommand-line utility.
The best way to get all these is to download everything from the source and then compile PHP yourself. This will ensure phpize Is built automatically, and headers will be in the include/ directory of your build tree.
You will also need the following P4 apps:
-
P4 API for PHP
-
P4 API for C/C++
Find the version of the P4 apps in the Perforce archive and download them.
The versions of both apps must be the same. To ensure you are getting the correct versions, download them both from same release folder in the archive. The latest release is 2025.1 which you can find here.
When downloading P4 API for C/C++, you must get a version of the app that matches:
-
Your system’s OpenSSL version
-
Your system’s C library version
For example, p4api-glibc2.12-openssl1.1.1.tgz for a system using OpenSSL 1.1.1 and with a C library version 2.12.
Build P4 API for PHP
When you have all the required files and apps, follow these steps:
-
Create an empty directory in which to extract the P4 API for PHP and P4 API for C/C++ archives.
-
Extract the archives.
-
Inside the
p4php-<version>directory, run the following in your terminal:Copyphpize
./configure --with-perforce=<path to P4 API for C/C++>
make -
To test the build, run the following in your terminal:
make testThe test harness requires the P4 Server executable in the current directory. -
Install P4 API for PHP by running the following in your terminal:
make installInstallation usually requires root or admin privileges. -
Edit
php.inito enable P4 API for PHP in PHP. Add the following line to thephp.inifile:-
extension=perforce.so;
-
-
Check this module loads correctly by running the following in your terminal:
php -m -
Verify the installation has installed correct by viewing the version details. Run the following in your terminal:
php --ri perforce.If you see the version details, P4 API for PHP has been installed correctly.