garoudan / phpmath
Library to run Mathematica functions through PHP. Virtually could run any non-graphical Mathematica function.
Installs: 22
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/garoudan/phpmath
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2025-10-11 19:20:05 UTC
README
PHPMath is a library to run Mathematica functions through PHP.
Example:
Input:
echo $phpmath->run("'Prime[1000]'");
Output:
7919
Requirements
This library uses php shell_exec function to do a call to Mathematica, so this function should be permitted.
This library usually aims *nix systems but we think it could run on any other systems (not tested).
- If shell_exec can run our
Shell.mathematicascript, should work.
Instructions
- Mathematica License¹:
- Copy your Mathematica® license to the PHP home folder (for example,
/var/www).- The license usually is on a hidden folder inside the licensed user
home (for example,
/home/user/.Mathematica). - In other words, for this example, the folder
.Mathematicainside/home/usershould be copied to/var/www. - Symlinks don't seem to be working.
- The license usually is on a hidden folder inside the licensed user
home (for example,
- Copy your Mathematica® license to the PHP home folder (for example,
- Composer:
- Put
"garoudan/phpmath": "dev-master"in yourcomposer.jsonrequire section. - Example of a full
composer.jsonfile:
- Put
{
"require": {
"garoudan/phpmath": "dev-master"
}
}
- Make sure the
Shell.mathematicahave read and execution permission².
sudo chmod 755 /path/to/the/vendor/of/your/project/garoudan/phpmath/core/Backend/Model/Mathematica/Shell.mathematica
- Start coding:
require_once 'path/to/your/composer/vendor/autoload.php';
use PHPMath\PHPMath;
$phpmath = new PHPMath;
echo $phpmath->run("Prime[1000]");
Enjoy.
Troubleshooting
- Was not possible make '.../Mathematica/Shell.mathematica' readable and executable:
- Make sure you did the step marked with ² above.
sudo chmod 755 /path/to/the/vendor/of/your/project/garoudan/phpmath/core/Backend/Model/Mathematica/Shell.mathematica
- Mathematica cannot find a valid password:
- Make sure you did the step marked with ¹ above.