garoudan / phpmath
通过 PHP 运行 Mathematica 函数的库。理论上可以运行任何非图形 Mathematica 函数。
dev-master
2017-01-23 00:49 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-14 13:58:22 UTC
README
PHPMath 是一个库,可以通过 Mathematica 函数通过 PHP 运行。
示例
输入
echo $phpmath->run("'Prime[1000]'");
输出
7919
要求
此库使用 php shell_exec
函数调用 Mathematica,因此应允许此函数。
此库通常针对 *nix 系统,但我们认为它可以在任何其他系统上运行(未经测试)。
- 如果 shell_exec 可以运行我们的
Shell.mathematica
脚本,则应该可以工作。
说明
- Mathematica 许可证¹
- 将您的 Mathematica® 许可证复制到 PHP 主目录(例如,
/var/www
)。- 许可证通常位于受许可用户家目录中的隐藏文件夹内(例如,
/home/user/.Mathematica
)。 - 换句话说,对于此示例,应将
/home/user
中的.Mathematica
文件夹复制到/var/www
。 - 符号链接似乎不起作用。
- 许可证通常位于受许可用户家目录中的隐藏文件夹内(例如,
- 将您的 Mathematica® 许可证复制到 PHP 主目录(例如,
- Composer
- 在您的
composer.json
的 require 部分中添加"garoudan/phpmath": "dev-master"
。 - 完整的
composer.json
文件示例
- 在您的
{
"require": {
"garoudan/phpmath": "dev-master"
}
}
- 确保
Shell.mathematica
有读取和执行权限²。
sudo chmod 755 /path/to/the/vendor/of/your/project/garoudan/phpmath/core/Backend/Model/Mathematica/Shell.mathematica
- 开始编码
require_once 'path/to/your/composer/vendor/autoload.php';
use PHPMath\PHPMath;
$phpmath = new PHPMath;
echo $phpmath->run("Prime[1000]");
享受。
故障排除
- 无法使 '.../Mathematica/Shell.mathematica' 可读和可执行:
- 确保您已完成上面标记为 ² 的步骤。
sudo chmod 755 /path/to/the/vendor/of/your/project/garoudan/phpmath/core/Backend/Model/Mathematica/Shell.mathematica
- Mathematica 找不到有效的密码:
- 确保您已完成上面标记为 ¹ 的步骤。