0

I am running WAMP Server 2.5 (32-bit) with PHP 5.5.12 on a Windows 7 SP1 64-bit machine. I am running Matlab R2014b.

I am trying to execute Matlab via PHP.

The Matlab function phptest.m is as follow:

function phptest
% Open file
fid = fopen('success.txt', 'wt');
%Print a test string
fprintf(fid, 'Test matlab function');
% Close file
fclose(fid);
% Quit MATLAB
quit force

When I execute from the command prompt:

matlab -wait -nosplash -sd "C:\wamp\www\testMatlab" -logfile logfile.txt -r "phptest;"

the code runs without problems and the file 'sucess.txt' is created.

However, if I try to execute via a php file:

<?php
$testStr = 'matlab -wait -nosplash -sd "C:\wamp\www\testMatlab" -logfile logfile.txt -r "phptest;"';
exec($testStr);
echo("Done!");
?>

The logfile shows the following error:

Severe: Error checking out license

Any help would be appreciated.

simonjdp
  • 3
  • 1

1 Answers1

0

You can force MATLAB to use a specific license file by running it with the -c flag:

'matlab -c "path/to/license" -wait -nosplash -sd "C:\wamp\www\testMatlab" -logfile logfile.txt -r "phptest;"';

matlab -c licensefile starts MATLAB using the specified license file. The licensefile argument can have the form port@host or it can be a colon-separated list of license filenames. This option causes the LM_LICENSE_FILE and MLM_LICENSE_FILE environment variables to be ignored.

See: http://www.mathworks.nl/help/matlab/ref/matlabwindows.html

0xMB
  • 871
  • 1
  • 8
  • 15
  • Thank you. The "-c" option seems to have solved the license checkout error, however, now the php page hangs in the browser. If I execute the same command (with the -c option) in the command prompt it still executes perfectly. Really baffled! – simonjdp Oct 16 '14 at 15:58
  • If you don't need the output of your script, you can execute your script in the background; http://php.net/manual/en/function.exec.php Also, check that your function is within the search path or startup folder of MATLAB. You specify -sd, but this option has been deprecated. Please check: http://www.mathworks.nl/help/matlab/matlab_env/matlab-startup-folder.html – 0xMB Oct 16 '14 at 16:48