Data & Workflow · Tables, pipelines, and notebooks
phpolars
Polars data frames for PHP
Install
pie install phpstats/phpolars
- Requires
- PIE
- Builds with
- Rust toolchain libclang
- Platforms
- Linux macOS NTS (non-thread-safe) PHP
phpolars is a native PHP extension, written in Rust, that brings the Polars columnar engine to PHP. PIE installs it as the php_polars extension for PHP 8.3, 8.4, and 8.5 on Linux and macOS.
phibble's PolarsTable holds a table in Polars through this extension, so phplyr pipelines can run in Polars. phibble and phplyr work without phpolars.
In phplyr's backend benchmark (Apple M5 Ultra, PHP 8.5.10, October 2026), pipelines on a PolarsTable ran 1.3 to 15 times faster than on an in-memory phibble data frame. The pipeline that filters with a PHP closure gained the least.
Example
use function Phpolars\{col, len, read_csv};
$sales = read_csv('sales.csv', tryParseDates: true);
$top = $sales
->filter(col('units')->gt(0))
->withColumns(col('units')->mul(col('price'))->alias('revenue'))
->groupBy('product', maintainOrder: true)
->agg(col('revenue')->sum()->round(2), ['orders' => len()], col('price')->mean()->round(2)->alias('avg_price'))
->sort('revenue', descending: true);
echo $top;
Output
shape: (4, 4)
┌─────────┬─────────┬────────┬───────────┐
│ product ┆ revenue ┆ orders ┆ avg_price │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ f64 ┆ u32 ┆ f64 │
╞═════════╪═════════╪════════╪═══════════╡
│ cherry ┆ 1307.38 ┆ 44 ┆ 4.09 │
│ banana ┆ 1285.76 ┆ 48 ┆ 4.35 │
│ apple ┆ 1227.68 ┆ 42 ┆ 4.38 │
│ date ┆ 1153.58 ┆ 41 ┆ 4.46 │
└─────────┴─────────┴────────┴───────────┘
Run it live
All vignettes →
Lazy queries over a large file
Scan a Parquet or CSV file with up to 5 million rows, let Polars push the filter and column selection into the scan, and compare the time with reading the whole file first.
phplyr pipelines on Polars
Run one phplyr pipeline on phibble's in-memory DataFrame and on a PolarsTable, check that the results agree, and compare the times.
Rolling windows and asof joins
Price a year of daily sales with an asof join, smooth it with a time-based rolling mean, and summarize it by month or quarter.
Polars pipeline
The same pipeline on an in-memory data frame and in Polars, with timings for up to 300,000 rows.