Awesome Open Source
Awesome Open Source

Tensor: Scientific Computing for PHP

PHP from Packagist Latest Stable Version PHP Build Extension Build Downloads from Packagist GitHub

A library and extension that provides objects for scientific computing in PHP.


Follow the instructions below to install either Tensor PHP or the Tensor extension.

Tensor PHP

Install Tensor PHP into your project with Composer:

$ composer require rubix/tensor

Tensor Extension

Install the Tensor extension via PECL:

$ pecl install tensor

Note: If both the library and extension are installed, the extension will take precedence.


  • PHP 7.4 or above

Optional To Compile Extension

Manually Compiling the Extension

Clone the repository locally using Git:

$ git clone

Make sure you have all the necessary build tools installed such as a C compiler and make tools. For example, on an Ubuntu linux system you can enter the following on the command line to install the necessary dependencies.

$ sudo apt-get install make gcc gfortran php-dev libopenblas-dev liblapacke-dev re2c build-essential

Then, change into the ext directory from the project root and run the following commands from the terminal. See this guide for more information on compiling PHP extensions with PHPize.

$ cd ./ext
$ phpize
$ ./configure
$ make
$ sudo make install

Finally, add the following line to your php.ini configuration to install the extension.

To confirm that the extension is loaded in PHP, you can run the following command.

php -m | grep tensor

Performance Comparison

Tensor Performance MNIST

Tensor Performance Benchmarks


Rubix ML is funded by donations from the community. You can become a sponsor by making a contribution to one of our funding sources below.


See for guidelines.


The code is licensed MIT and the documentation is licensed CC BY-NC 4.0.

Related Awesome Lists
Top Programming Languages

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Php (298,029
Machine Learning (40,892
Matrix (10,866
Statistics (10,845
Mathematics (10,277
Vector (10,061
Scientific (2,802
Tensor (2,383
Arithmetic (1,933
Linear Algebra (1,129
Scientific Computing (770
Php Extension (622
Lapack (581
Matrix Factorization (568
Matrix Multiplication (288
Multithreaded (111
Matrix Decompositions (44
Rubix (4