garoudan / phpmath
Library to run Mathematica functions through PHP. Virtually could run any non-graphical Mathematica function.
dev-master
2017-01-23 00:49 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2025-01-04 15:26:11 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.mathematica
script, 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
.Mathematica
inside/home/user
should 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.json
require section. - Example of a full
composer.json
file:
- Put
{
"require": {
"garoudan/phpmath": "dev-master"
}
}
- Make sure the
Shell.mathematica
have 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.