https://github.com/rukanuel/trace
A native PHP extension to get Cloudflare's trace data.
https://github.com/rukanuel/trace
cloudflare php trace
Last synced: 7 months ago
JSON representation
A native PHP extension to get Cloudflare's trace data.
- Host: GitHub
- URL: https://github.com/rukanuel/trace
- Owner: rukanuel
- License: mit
- Created: 2024-12-28T23:46:01.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-29T00:13:37.000Z (about 1 year ago)
- Last Synced: 2024-12-29T01:17:25.153Z (about 1 year ago)
- Topics: cloudflare, php, trace
- Language: Rust
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Trace for PHP

**Trace for PHP** is a native PHP extension designed to fetch Cloudflare's trace data efficiently and easily.
## Features
- Provides a simple way to access Cloudflare's trace data from PHP.
- Lightweight and efficient native extension.
- Easy-to-use JSON decoding for structured data.
## Prerequisites
- **Supported PHP Versions**: Ensure you have PHP 8.2 or newer installed. The installation instructions use paths specific to PHP 8.2 but can be adjusted for other versions.
- **PHP Extensions Directory**: The extension must be installed in the correct `extension_dir` for your PHP installation. Instructions to find this directory are included below.
## Usage
After installing the extension, you can fetch trace data with the following snippet:
```php
$foo = trace();
echo $foo['clientIp'];
```
For more advanced usage, refer to the [example](example.php) file in the project.
For example response see [JSON](example.json).
## Installation
Follow these steps to install the Trace extension for PHP:
### Step 1: Find PHP Version and Extensions Directory
Run the following commands to determine your PHP version and the location of the extensions directory:
```sh
php -v && php -i | grep extension_dir
```
### Step 2: Install the Extension
Run the command below, ensuring you replace paths with the correct values for your PHP installation. The provided example is for PHP 8.2.
```sh
wget https://github.com/rukanuel/trace/releases/download/v1.1a/libtrace.so &&
sudo mv -f libtrace.so /usr/lib/php/20220829/ &&
grep -q "extension=/usr/lib/php/20220829/libtrace.so" /etc/php/8.2/cli/php.ini ||
echo "extension=/usr/lib/php/20220829/libtrace.so" |
sudo tee -a /etc/php/8.2/cli/php.ini
```
**Notes**
- Replace `/usr/lib/php/20220829/` with the path to your PHP extensions directory if different.
- Update `/etc/php/8.2/cli/php.ini` to match the PHP version and configuration you are using.
### Step 3: Verify the Extension
Run the following command to confirm the extension is loaded:
```sh
php -m | grep trace
```
## Development
If you want to build or modify the extension, follow these steps:
### Step 1: Install Development Tools and Dependencies
Run the following command to install the required tools and libraries:
```sh
sudo apt update && sudo apt install -y php php-dev libclang-dev clang
```
### Step 2: Clone the Repository
Clone the repository from GitHub:
```sh
git clone https://github.com/rukanuel/trace.git
cd trace
```
### Step 3: Build the Extension
Ensure you have Rust and Cargo installed. If not, you can install them using [Rustup](https://rustup.rs/):
```sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
export PATH="$HOME/.cargo/bin:$PATH"
source ~/.bashrc
```
Then, build the extension:
```sh
cargo build
```
The compiled extension will be located at `target/debug/libtrace.so`.
### Step 4: Test the Extension
Use the following command to test the extension without installing it globally:
```sh
php -d extension=./target/debug/libtrace.so example.php
```
## License
This project is licensed under the [MIT](LICENSE) license.