使用php在网页执行matlab
通过php调用linux命令,可以实现远程调用matlab.
试验环境:Fedora16, matlab2012b linux version, Google chrome 18.0.1025.108 beta
以下代码实现了在网页输入matlab命令并显示执行结果。注意:如果不加-nodisplay选项,会出现" no display specified"的警告,当然可以在执行matlab命令之前unset DISPLAY也可以直接在terminal执行matlab。
如果你仅仅想远程调用matlab函数,可以参考mathworks的php webservice相关文档,此处也可以参考官方关于python调用的文档。
以下代码对于plot()等绘图命令会出现{Warning: Objects of graph2d.lineseries class exist - not clearing this class or any of its super-classes}错误,目前未解决(也就是无法绘图)。但是通过ssh远程登陆服务器调用相同命令可以plot并save图像,不解。
";//$command="/usr/local/MATLAB/R2012a/bin/matlab -r "."\"".$cmd."\"";shell_exec("unset DISPLAY");//删除DISPLAY环境变量$out = shell_exec($command);$str=" Copyright 1984-2012 The MathWorks, Inc. R2012a (7.14.0.739) 32-bit (glnx86) February 9, 2012 To get started, type one of these: helpwin, helpdesk, or demo.For product information, visit www.mathworks.com.";$out=ltrim($out,$str);$out=rtrim($out,">>");echo $out;}?>
相关截图:
输入sin(1:10)进行简单计算
输入ver命令获取版本信息
直接终端运行
参考资料:
mathwork关于matlab启动参数的介绍:
http://www.mathworks.cn/help/techdoc/matlab_env/f8-4994.html
SpecifyingMATLAB Startup Options
Youcan specify startup options (also called command flags or commandline switches) that instruct the MATLAB program to perform certainoperations when you start it. On all platforms, you specify theoptions as arguments to the matlab command when you start is at theoperating system prompt. For example, the following starts MATLAB andsuppresses the display of the splash screen.
matlab-nosplash
OnWindows platforms, you can precede a startup option with either ahyphen (-) or a slash (/). For example, -nosplash and /nosplash areequivalent.
Onall platforms, you can also specify startup options using a MATLABstartup file—see Specifying Startup Options in the MATLAB StartupFile
OnWindows platforms, you can specify startup options in the MATLABshortcut—see Including Startup Options in a Shortcut on WindowsSystems.
IncludingStartup Options in a Shortcut on Windows Systems
Youcan add selected startup options (also called command flags orswitches for the command line) to the target path for your shortcutin the Windows environment for MATLAB. For more information about theoptions, see CommonlyUsed Startup Options.
Touse startup options for the MATLAB shortcut icon in a Windowsenvironment, follow these steps:
Right-clickthe shortcut icon for MATLAB
andselect Properties from the context menu. TheProperties dialog box for MATLAB opens to the Shortcut pane.
Inthe Target field,after the target path for matlab.exe,add the startup option, and click OK.For example, adding -r"filename" runsthe MATLAB code file filenameafterstartup.
Thisexample instructs MATLAB to automatically run the file results afterstartup, whereresults.m isin the startup folder or on the search path for MATLAB. The statementin the Target fieldmight appear as
<span style="color:#000000"><span style="font-family:courier new,courier,monospace">C:\Program Files\MATLAB\R2010b\bin\matlab.exe -r "results"</span></span>
Includethe statement in double quotation marks ("statement").Use only the file name, not the file extension or path name. Forexample, MATLAB produces an error when you run
<span style="color:#000000"><span style="font-family:courier new,courier,monospace">... matlab.exe -r "D:\results.m"</span></span>
Usesemicolons or commas to separate multiple statements. This examplechanges the format to short,and then runs the MATLAB code file results:
<span style="color:#000000"><span style="font-family:courier new,courier,monospace">... matlab.exe -r "format('short');results"</span></span>
Separatemultiple options with spaces. This example starts MATLAB withoutdisplaying the splash screen, and then runs the MATLAB codefile results:
<span style="color:#000000"><span style="font-family:courier new,courier,monospace">... matlab.exe -nosplash -r "results"</span></span>
SpecifyingStartup Options in the MATLAB Startup File
Atstartup, MATLAB automatically executes the file matlabrc.m and,if it exists,startup.m.The file matlabrc.m,which is in the matlabroot/toolbox/local folder,is reserved for use by MathWorks and by the system manager onmultiuser systems.
Thefile startup.m isfor you to specify startup options. For example, you can modify thedefault search path, predefine variables in your workspace, or definedefaults for Handle Graphics? objects.Use the following statements in a startup.m fileto add the specified folder, /home/username/mytools,to the search path, and to change the current folder to mytools uponstartup.
<span style="font-family:DejaVu Sans Mono,monospace"><span style="font-family:'courier new',courier,monospace"><span style="font-size:9pt">addpath /home/</span></span><tt class="western"><span style="font-family:'courier new',courier,monospace"><span style="font-size:9pt"><em>username</em></span></span></tt><span style="font-family:'courier new',courier,monospace"><span style="font-size:9pt">/mytools</span></span></span><span style="font-family:DejaVu Sans Mono,monospace"><span style="font-family:'courier new',courier,monospace"><span style="font-size:9pt">cd /home/</span></span><tt class="western"><span style="font-family:'courier new',courier,monospace"><span style="font-size:9pt"><em>username</em></span></span></tt><span style="font-family:'courier new',courier,monospace"><span style="font-size:9pt">/mytools</span></span></span>
<span style="font-size:9pt; font-family:'Times New Roman',serif"><span style="font-family:Verdana,Arial,Helvetica,sans-serif"><span style="font-size:9pt">Placethe </span></span></span><tt class="western" style="font-size:9pt"><span style="font-family:'courier new',courier,monospace"><span style="font-size:9pt">startup.m</span></span></tt><span style="font-size:9pt; font-family:'Times New Roman',serif"><span style="font-family:Verdana,Arial,Helvetica,sans-serif"><span style="font-size:9pt"> filein the default or current startup folder, which is where MATLAB firstlooks for it. For more information, see .</span></span></span>
CommonlyUsed Startup Options
Thefollowing table provides a list of some commonly used startup optionsfor both Windows and UNIX? platforms.For more information, including a complete list of startup options,see the matlab(Windows) referencepage or the matlab(UNIX) referencepage.
Platform |
Option |
Description |
---|---|---|
All |
-clicensefile |
Set LM_LICENSE_FILE to licensefile.It can have the form [email protected]. |
All |
-hor -help |
Displaystartup options (without starting MATLAB). |
All |
-logfile"logfilename" |
Automaticallywrite output from MATLAB to the specified log file. |
Windowsplatforms |
-minimize |
StartMATLAB with the desktop minimized. Any desktop tools or documentsthat were undocked when MATLAB was last closed will not beminimized upon startup. |
UNIXplatforms |
-nojvm |
StartMATLAB without loading the Sun Microsystems JVM? software. Thisminimizes memory usage and improves initial startup speed, butrestricts functionality. With nojvm,you cannot use the desktop, figures, or any tools that requireJava software. Forexample, you cannot set preferences if you start MATLAB withthe -nojvm option.However, you can start MATLAB once without the -nojvm option,set the preference, and quit MATLAB. MATLAB remembers thatpreference when you start it again, even if you usethe-nojvm option. |
All |
-nosplash |
StartMATLAB without displaying its splash screen. |
All |
-r"statement" |
Automaticallyrun the specified statement immediately after MATLAB starts. Thisis sometimes referred to as calling MATLAB in batch mode. Filesyou run must be in the startup folder for MATLAB or on the searchpath. Do not include path names or file extensions. Enclose thestatement in double quotation marks ("statement").Use semicolons or commas to separate multiple statements |
All |
-singleCompThread |
LimitMATLAB to a single computational thread. By default, Windowsmakes use of the multithreading capabilities of the computer onwhich it is running. |
PassingPerl Variables on Startup
Youcan pass Perl variables to MATLAB on startup by usingthe -r optionof the matlabfunction.For example, assume a MATLAB function test thattakes one input variable:
<span style="color:#000000"><span style="font-family:courier new,courier,monospace">function test(x)</span></span>
Tostart MATLAB with the function test,use the command
<span style="color:#000000"><span style="font-family:courier new,courier,monospace">matlab -r "test(10)"</span></span>
Onsome platforms, you might need to use double quotation marks:
<span style="color:#000000"><span style="font-family:courier new,courier,monospace">matlab -r "test(10)"</span></span>
Thiscommand starts MATLAB and runs test withthe input argument 10.
Topass a Perl variable instead of a constant as the input parameter,follow these steps.
-
Createa Perl script such as
<span style="color:#000000"> <span style="font-family:DejaVu Sans Mono,monospace"><span style="font-family:courier new,courier,monospace"><span style="font-size:12px; font-size:9pt">#!/usr/local/bin/perl</span></span></span></span><span style="color:#000000"> <span style="font-family:DejaVu Sans Mono,monospace"><span style="font-family:courier new,courier,monospace"><span style="font-size:12px; font-size:9pt">$val = 10; </span></span></span></span><span style="color:#000000"> <span style="font-family:DejaVu Sans Mono,monospace"><span style="font-family:courier new,courier,monospace"><span style="font-size:12px; font-size:9pt">system('matlab -r "test(' . ${val} . ')"');</span></span></span></span>
Invokethe Perl script at the prompt using a Perl interpreter.
Formore information, see the matlab(Windows) or matlab(UNIX) referencepage.
Startupand Calling Java Software from the MATLAB Program
Whenthe MATLAB program starts, it constructs the class path for SunMicrosystems Java software using librarypath.txt aswell as classpath.txt.If you call Java software from MATLAB, see more about this in TheJava Class Path and LocatingNative Method Libraries inthe MATLAB External Interfaces documentation.
===============================================================================================================================
http://narnia.cs.ttu.edu/drupal/node/41
RunningMATLAB without graphic interface
Interactiveover SSH
StartMATLAB using the command:
<span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">matlab -nodisplay -nojvm</span></span></span>
Runninga MATLAB script over SSH
Inthis case, you don't even need a MATLAB Prompt to interact with.
<span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">matlab -nodisplay -nojvm -r a_code > matlab.out</span></span></span>
YourMATLAB program should have the file name <span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px; font-size:10pt">a_code.m</span></span></span>
(youcan change it to whatever name you like. But when you tell MATLAB torun it, omit the <span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px; font-size:10pt">.m</span></span></span>
suffix.)The <span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px; font-size:10pt">>matlab.out</span></span></span>
partredirects the output to a file rather than showing on your Linux/MacOS X terminal. This way is preferred because you have a record onwhat is happening.
Runninga MATLAB script with input variables over SSH
First,go to the directory containing the MATLAB script that defines thefunction (or, fancier, add that directory into MATLAB PATH byediting your MATLABPATH environment variable or pathdef.m file).Then, run like this
<span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">matlab -nodisplay -nojvm -r "my_function(10)"</span></span></span>
Again,you can redirect the output to a file.
Youcan also write a Shell, Perl or Python script to do so. MATLAB givesan example using Perlat http://www.mathworks.com/help/techdoc/matlab_env/f8-4994.html
OnSun Grid Engine (SGE)-powered cluster
Writea job script below and submit it using <span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px; font-size:10pt">qsub</span></span></span>
<span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">#!/bin/sh</span></span></span><span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">#$ -V</span></span></span><span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">#$ -cwd</span></span></span><span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">#$ -S /bin/bash</span></span></span><span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">#$ -N matlab</span></span></span><span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">#$ -o $JOB_NAME.o$JOB_ID</span></span></span><span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">#$ -e $JOB_NAME.e$JOB_ID</span></span></span><span style="color:#222222"><span style="font-family:Helvetica,sans-serif"><span style="font-size:12px">#$ -q normal </span></span></span><span style="color:#222222"><span style="font-family:Helvetica,sans-"></span></span>

데이터베이스 스토리지 세션 사용의 주요 장점에는 지속성, 확장 성 및 보안이 포함됩니다. 1. 지속성 : 서버가 다시 시작 되더라도 세션 데이터는 변경되지 않아도됩니다. 2. 확장 성 : 분산 시스템에 적용하여 세션 데이터가 여러 서버간에 동기화되도록합니다. 3. 보안 : 데이터베이스는 민감한 정보를 보호하기 위해 암호화 된 스토리지를 제공합니다.

SessionHandlerInterface 인터페이스를 구현하여 PHP에서 사용자 정의 세션 처리 구현을 수행 할 수 있습니다. 특정 단계에는 다음이 포함됩니다. 1) CustomsessionHandler와 같은 SessionHandlerInterface를 구현하는 클래스 만들기; 2) 인터페이스의 방법 (예 : Open, Close, Read, Write, Despare, GC)의 수명주기 및 세션 데이터의 저장 방법을 정의하기 위해 방법을 다시 작성합니다. 3) PHP 스크립트에 사용자 정의 세션 프로세서를 등록하고 세션을 시작하십시오. 이를 통해 MySQL 및 Redis와 같은 미디어에 데이터를 저장하여 성능, 보안 및 확장 성을 향상시킬 수 있습니다.

SessionId는 웹 애플리케이션에 사용되는 메커니즘으로 사용자 세션 상태를 추적합니다. 1. 사용자와 서버 간의 여러 상호 작용 중에 사용자의 신원 정보를 유지하는 데 사용되는 무작위로 생성 된 문자열입니다. 2. 서버는 쿠키 또는 URL 매개 변수를 통해 클라이언트로 생성하여 보낸다. 3. 생성은 일반적으로 임의의 알고리즘을 사용하여 독창성과 예측 불가능 성을 보장합니다. 4. 실제 개발에서 Redis와 같은 메모리 내 데이터베이스를 사용하여 세션 데이터를 저장하여 성능 및 보안을 향상시킬 수 있습니다.

JWT 또는 쿠키를 사용하여 API와 같은 무국적 환경에서 세션을 관리 할 수 있습니다. 1. JWT는 무국적자 및 확장 성에 적합하지만 빅 데이터와 관련하여 크기가 크다. 2. 쿠키는보다 전통적이고 구현하기 쉽지만 보안을 보장하기 위해주의해서 구성해야합니다.

세션 관련 XSS 공격으로부터 응용 프로그램을 보호하려면 다음 조치가 필요합니다. 1. 세션 쿠키를 보호하기 위해 Httponly 및 Secure 플래그를 설정하십시오. 2. 모든 사용자 입력에 대한 내보내기 코드. 3. 스크립트 소스를 제한하기 위해 컨텐츠 보안 정책 (CSP)을 구현하십시오. 이러한 정책을 통해 세션 관련 XSS 공격을 효과적으로 보호 할 수 있으며 사용자 데이터가 보장 될 수 있습니다.

PHP 세션 성능을 최적화하는 방법 : 1. 지연 세션 시작, 2. 데이터베이스를 사용하여 세션을 저장, 3. 세션 데이터 압축, 4. 세션 수명주기 관리 및 5. 세션 공유 구현. 이러한 전략은 높은 동시성 환경에서 응용의 효율성을 크게 향상시킬 수 있습니다.

THESESSION.GC_MAXLIFETIMESETTINGINSTTINGTINGSTINGTERMINESTERMINESTERSTINGSESSIONDATA, SETINSECONDS.1) IT'SCONFIGUDEDINPHP.INIORVIAINI_SET ()

PHP에서는 Session_Name () 함수를 사용하여 세션 이름을 구성 할 수 있습니다. 특정 단계는 다음과 같습니다. 1. Session_Name () 함수를 사용하여 Session_Name ( "my_session")과 같은 세션 이름을 설정하십시오. 2. 세션 이름을 설정 한 후 세션을 시작하여 세션을 시작하십시오. 세션 이름을 구성하면 여러 응용 프로그램 간의 세션 데이터 충돌을 피하고 보안을 향상시킬 수 있지만 세션 이름의 독창성, 보안, 길이 및 설정 타이밍에주의를 기울일 수 있습니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는
