help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to pass parameter from PHP to Octave?


From: Oliver Heimlich
Subject: Re: How to pass parameter from PHP to Octave?
Date: Wed, 29 Jul 2015 18:49:32 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0

On 29.07.2015 14:41, deepus wrote:
How to pass parameter from PHP to Octave

My PHP code is:* test.php*

/$a = 3;
$b = 4;
$cmd = "C:\Octave\Octave4\bin\octave-cli C:\wamp\www\dspace\sr.m $a $b";
$ex = exec($cmd, $op);
var_dump($ex);
var_dump($op); /

My Octave code:* sr.m*

/# how I retrieve the parameters a, b
sqrt(a^2 + b^2)/


I want to pass the variables $a and $b from the PHP code to Octave code. I
already define the variable in test.php and my problem is how to retrieve
the variable in octave code (sr.m).

In python we can retrieve the parameter as

/a = float(sys.argv[1])
b = float(sys.argv[2])/

Like that how can I retrieve the parameters in octave code. I think the
question is clear.

Please help me...


Hello,

there are ways to call octave over cli, but this would be very slow and you would introduce errors because of number conversions.

You could run octave as a socket server, connect with a php client, pass the parameters and receive the result. This is very fast and provides perfect accuracy.

You can use attached scripts and customize them to your needs. The scripts pass parameters and results as binary64 numbers. In the example you have to ...

1. start octave
2. make sure that the sockets package is installed (pkg install -forge sockets)
3. run the server.m script
4. use callOctave(3.0, 4.0) in PHP to receive an array with one element: 5.0. The server script currently executes the hypot functions from your example.

Best regards
Oliver

Attachment: client.php
Description: application/php

Attachment: server.m
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]