声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

声振论坛 展示 基础理论 查看内容

使用php在网页执行matlab

2012-10-18 06:57| 发布者: aspen| 查看: 14827| 评论: 0|原作者: Jillian|来自: 振动论坛

摘要: 目录 IncludingStartup Options in a Shortcut on Windows Systems SpecifyingStartup Options in the MATLAB Startup File CommonlyUsed Startup Options PassingPerl Variables on Startup Startupand Callin ...
CallingMATLAB from PHP
http://mem.bio.pitt.edu/content/calling-matlab-php
Submittedby keithc on Mon, 08/23/2010 - 15:26
Iwanted to run a MATLAB command from PHP that would generate afigure, save it to an image file, and display that image in thewebpage. Here is the process I used:
      1. Mostnew MATLAB licenses only allow a single specified user to startthe application at any time. If you want to call MATLAB from thecommand-line from an interface like PHP (that for security reasonsis run as another system user), one way to get around thislicensing issue is to masquerade as the licensed user using sudo:
  1. sudo-H licenseduser command
复制代码
The-H is necessary for the HOME environment variables to be changedto the target user.
      2. SincePHP won't have a TTY terminal associated with it, you'll have togive the system user that runs PHP/apache the NOPASSWD flag in thesudoers file. Start editing the sudoers file by running
  1. sudovisudo
复制代码
Thenadd the following line:
  1. apache-userALL=NOPASSWD: /usr/local/bin/matlab
复制代码
3. Nowyou should craft your exec() call in PHP. The basic syntax forstarting a MATLAB process in the backgroundis:
  1. /usr/local/bin/matlab-r "command;exit;"
复制代码
Notethat the "exit;" here is necessary so that the MATLABprocess will quit after processing. To run this from PHP we willuse the following command:
  1. $command= "sudo -H licenseduser /usr/local/bin/matlab -r"command;exit;"
复制代码
4. Additionally,if you want to be able to save graphics, I found it necessary toprepend the command with:
  1. DISPLAY="";exportDISPLAY;
复制代码
AndI set the Renderer variable for any Figure objects in MATLAB to"painters" (the default is often opengl, which will notwork for background processes).
Pleasenote that there are security issues in giving sudo privileges toyour apache/webserver user, especially with NOPASSWD.

本文内容由 Jillian 提供

123456789

最新评论

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-24 21:26 , Processed in 0.037957 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部