Calling an executable for processing some data sent from PHP

This is a discussion on Calling an executable for processing some data sent from PHP within the PHP General forums, part of the PHP Programming Forums category; Ok, so I have a PHP script, and I also have a program written in Pascal, it's compiled in ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-15-2007
Dan
 
Posts: n/a
Default Calling an executable for processing some data sent from PHP

Ok, so I have a PHP script, and I also have a program written in Pascal,
it's compiled in the native executable for whatever OS the server is
running.

I want to have the user input info and then send that info to the Pascal
program to call a function and send the info as parameters.

Is there any sort of server side call I can do to do this? Or is my only
option making some sort of connection such as SOAP between PHP and the
Program?
Reply With Quote
  #2 (permalink)  
Old 06-15-2007
Tijnema
 
Posts: n/a
Default Re: [PHP] Calling an executable for processing some data sent from PHP

On 6/15/07, Dan <frozendice@gmail.com> wrote:
> Ok, so I have a PHP script, and I also have a program written in Pascal,
> it's compiled in the native executable for whatever OS the server is
> running.
>
> I want to have the user input info and then send that info to the Pascal
> program to call a function and send the info as parameters.
>
> Is there any sort of server side call I can do to do this? Or is my only
> option making some sort of connection such as SOAP between PHP and the
> Program?
>

Yes, you will end up with AJAX code I think, or if you don't care to
load new page, you can simply click on a link and let PHP handle an
exec/system call.

Tijnema
Reply With Quote
  #3 (permalink)  
Old 06-15-2007
Richard Heyes
 
Posts: n/a
Default Re: [PHP] Calling an executable for processing some data sent fromPHP

Dan wrote:
> Ok, so I have a PHP script, and I also have a program written in Pascal,
> it's compiled in the native executable for whatever OS the server is
> running.
>
> I want to have the user input info and then send that info to the Pascal
> program to call a function and send the info as parameters.
>
> Is there any sort of server side call I can do to do this? Or is my
> only option making some sort of connection such as SOAP between PHP and
> the Program?


You could try shell_exec(). Eg:

$output = shell_exec('.usr/bin/foo ' . escapeshellarg($_POST['foo']));

--
Richard Heyes
0844 801 1072
http://www.websupportsolutions.co.uk
Knowledge Base and HelpDesk software
Reply With Quote
  #4 (permalink)  
Old 06-15-2007
Daniel Brown
 
Posts: n/a
Default Re: [PHP] Calling an executable for processing some data sent from PHP

On 6/15/07, Dan <frozendice@gmail.com> wrote:
> Ok, so I have a PHP script, and I also have a program written in Pascal,
> it's compiled in the native executable for whatever OS the server is
> running.
>
> I want to have the user input info and then send that info to the Pascal
> program to call a function and send the info as parameters.
>
> Is there any sort of server side call I can do to do this? Or is my only
> option making some sort of connection such as SOAP between PHP and the
> Program?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


RTFM for exec(), system(), passthru(), et cetera.

<?
exec('pascal-file '.$_POST['user_command'],$ret);
$ret == 1 ? 'Error detected' ? '';
?>


--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Reply With Quote
  #5 (permalink)  
Old 06-15-2007
Dan
 
Posts: n/a
Default Re: [PHP] Calling an executable for processing some data sent from PHP

Will that script also work on Apache in Windows? OS X? Just checking
because the backend and front end both need to be able to be installed on
any OS.

Also I looked at exec(), system(), and passthru(); they all let you execute
a executable file but I don't see any way of passing parameters in any of
those functions, can you do that?

- Daniel

""Daniel Brown"" <parasane@gmail.com> wrote in message
news:ab5568160706151311m3327bbccha02e3f5ca96255d8@ mail.gmail.com...
> On 6/15/07, Dan <frozendice@gmail.com> wrote:
>> Ok, so I have a PHP script, and I also have a program written in Pascal,
>> it's compiled in the native executable for whatever OS the server is
>> running.
>>
>> I want to have the user input info and then send that info to the Pascal
>> program to call a function and send the info as parameters.
>>
>> Is there any sort of server side call I can do to do this? Or is my only
>> option making some sort of connection such as SOAP between PHP and the
>> Program?
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>

>
> RTFM for exec(), system(), passthru(), et cetera.
>
> <?
> exec('pascal-file '.$_POST['user_command'],$ret);
> $ret == 1 ? 'Error detected' ? '';
> ?>
>
>
> --
> Daniel P. Brown
> [office] (570-) 587-7080 Ext. 272
> [mobile] (570-) 766-8107

Reply With Quote
  #6 (permalink)  
Old 06-15-2007
Daniel Brown
 
Posts: n/a
Default Re: [PHP] Calling an executable for processing some data sent from PHP

On 6/15/07, Dan <frozendice@gmail.com> wrote:
> Will that script also work on Apache in Windows? OS X? Just checking
> because the backend and front end both need to be able to be installed on
> any OS.
>
> Also I looked at exec(), system(), and passthru(); they all let you execute
> a executable file but I don't see any way of passing parameters in any of
> those functions, can you do that?
>
> - Daniel
>
> ""Daniel Brown"" <parasane@gmail.com> wrote in message
> news:ab5568160706151311m3327bbccha02e3f5ca96255d8@ mail.gmail.com...
> > On 6/15/07, Dan <frozendice@gmail.com> wrote:
> >> Ok, so I have a PHP script, and I also have a program written in Pascal,
> >> it's compiled in the native executable for whatever OS the server is
> >> running.
> >>
> >> I want to have the user input info and then send that info to the Pascal
> >> program to call a function and send the info as parameters.
> >>
> >> Is there any sort of server side call I can do to do this? Or is my only
> >> option making some sort of connection such as SOAP between PHP and the
> >> Program?
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>

> >
> > RTFM for exec(), system(), passthru(), et cetera.
> >
> > <?
> > exec('pascal-file '.$_POST['user_command'],$ret);
> > $ret == 1 ? 'Error detected' ? '';
> > ?>
> >
> >
> > --
> > Daniel P. Brown
> > [office] (570-) 587-7080 Ext. 272
> > [mobile] (570-) 766-8107

>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Yeah, the first parameter of each function, where you call the
executable directly, just has to include the parameters you want to
pass to the binary.

For example, if you wanted to do the following:
netstat -pnt
ls -al|grep -i php
mv file1.php backups/file2.php

You would (respectively) simply do the following:
exec('netstat -pnt',$ret);
exec('ls -al|grep -i php',$ret);
exec('mv file1.php backups/file2.php',$ret);

Then just eval $ret to see if it was successful (0) or not (1).

If you wanted to allow a user to specify parameters, it would be
done like so:

[php]
L> File: form.php
<?
if($_POST['parameters']) {
exec('/path/to/pascal-binary '.escapeshellarg($_POST['parameters']),$ret);
$ret == 0 ? "Success!" : "Failure!";
exit;
}
?>
<FORM METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF;?>">
Parameters: <INPUT TYPE="TEXT" NAME="parameters"><BR />
<INPUT TYPE="SUBMIT" VALUE="Process Now">
</FORM>

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Reply With Quote
  #7 (permalink)  
Old 06-15-2007
Dan
 
Posts: n/a
Default Re: [PHP] Calling an executable for processing some data sent from PHP

Wow, thanks for the code and the fast response! :) Although maybe I should
clarify my probem a bit more, I'm trying to run a program, but I want it to
stay open so that I can call functions later.

When the user "opens" a file, it's uploaded to a folder where PHP can access
it, then PHP would call the Pascal program which would parse the file, and
create a new object for that data, which later functions would access and do
computation on. Like a user woud click Compute Subsets and that would
somehow trigger the function Compute_Subsets on that object. Any way I
could do something like this?

My ugly way to do it would be to do an exec() to call an executable to parse
the file and make an object of it then run the function that I needed to
every time a function was called. The code base for this would be horrible
to maintain and incredibly slow.

Is there some way I could keep the program open and give it further
arguments?
""Daniel Brown"" <parasane@gmail.com> wrote in message
news:ab5568160706151352l7f0c002ah700d712088e90115@ mail.gmail.com...
> On 6/15/07, Dan <frozendice@gmail.com> wrote:
>> Will that script also work on Apache in Windows? OS X? Just checking
>> because the backend and front end both need to be able to be installed on
>> any OS.
>>
>> Also I looked at exec(), system(), and passthru(); they all let you
>> execute
>> a executable file but I don't see any way of passing parameters in any of
>> those functions, can you do that?
>>
>> - Daniel
>>
>> ""Daniel Brown"" <parasane@gmail.com> wrote in message
>> news:ab5568160706151311m3327bbccha02e3f5ca96255d8@ mail.gmail.com...
>> > On 6/15/07, Dan <frozendice@gmail.com> wrote:
>> >> Ok, so I have a PHP script, and I also have a program written in
>> >> Pascal,
>> >> it's compiled in the native executable for whatever OS the server is
>> >> running.
>> >>
>> >> I want to have the user input info and then send that info to the
>> >> Pascal
>> >> program to call a function and send the info as parameters.
>> >>
>> >> Is there any sort of server side call I can do to do this? Or is my
>> >> only
>> >> option making some sort of connection such as SOAP between PHP and the
>> >> Program?
>> >>
>> >> --
>> >> PHP General Mailing List (http://www.php.net/)
>> >> To unsubscribe, visit: http://www.php.net/unsub.php
>> >>
>> >>
>> >
>> > RTFM for exec(), system(), passthru(), et cetera.
>> >
>> > <?
>> > exec('pascal-file '.$_POST['user_command'],$ret);
>> > $ret == 1 ? 'Error detected' ? '';
>> > ?>
>> >
>> >
>> > --
>> > Daniel P. Brown
>> > [office] (570-) 587-7080 Ext. 272
>> > [mobile] (570-) 766-8107

>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>

>
> Yeah, the first parameter of each function, where you call the
> executable directly, just has to include the parameters you want to
> pass to the binary.
>
> For example, if you wanted to do the following:
> netstat -pnt
> ls -al|grep -i php
> mv file1.php backups/file2.php
>
> You would (respectively) simply do the following:
> exec('netstat -pnt',$ret);
> exec('ls -al|grep -i php',$ret);
> exec('mv file1.php backups/file2.php',$ret);
>
> Then just eval $ret to see if it was successful (0) or not (1).
>
> If you wanted to allow a user to specify parameters, it would be
> done like so:
>
> [php]
> L> File: form.php
> <?
> if($_POST['parameters']) {
> exec('/path/to/pascal-binary
> '.escapeshellarg($_POST['parameters']),$ret);
> $ret == 0 ? "Success!" : "Failure!";
> exit;
> }
> ?>
> <FORM METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF;?>">
> Parameters: <INPUT TYPE="TEXT" NAME="parameters"><BR />
> <INPUT TYPE="SUBMIT" VALUE="Process Now">
> </FORM>
>
> --
> Daniel P. Brown
> [office] (570-) 587-7080 Ext. 272
> [mobile] (570-) 766-8107

Reply With Quote
  #8 (permalink)  
Old 06-15-2007
Daniel Brown
 
Posts: n/a
Default Re: [PHP] Calling an executable for processing some data sent from PHP

On 6/15/07, Dan <frozendice@gmail.com> wrote:
> Wow, thanks for the code and the fast response! :) Although maybe I should
> clarify my probem a bit more, I'm trying to run a program, but I want it to
> stay open so that I can call functions later.
>
> When the user "opens" a file, it's uploaded to a folder where PHP can access
> it, then PHP would call the Pascal program which would parse the file, and
> create a new object for that data, which later functions would access and do
> computation on. Like a user woud click Compute Subsets and that would
> somehow trigger the function Compute_Subsets on that object. Any way I
> could do something like this?
>
> My ugly way to do it would be to do an exec() to call an executable to parse
> the file and make an object of it then run the function that I needed to
> every time a function was called. The code base for this would be horrible
> to maintain and incredibly slow.
>
> Is there some way I could keep the program open and give it further
> arguments?
> ""Daniel Brown"" <parasane@gmail.com> wrote in message
> news:ab5568160706151352l7f0c002ah700d712088e90115@ mail.gmail.com...
> > On 6/15/07, Dan <frozendice@gmail.com> wrote:
> >> Will that script also work on Apache in Windows? OS X? Just checking
> >> because the backend and front end both need to be able to be installed on
> >> any OS.
> >>
> >> Also I looked at exec(), system(), and passthru(); they all let you
> >> execute
> >> a executable file but I don't see any way of passing parameters in any of
> >> those functions, can you do that?
> >>
> >> - Daniel
> >>
> >> ""Daniel Brown"" <parasane@gmail.com> wrote in message
> >> news:ab5568160706151311m3327bbccha02e3f5ca96255d8@ mail.gmail.com...
> >> > On 6/15/07, Dan <frozendice@gmail.com> wrote:
> >> >> Ok, so I have a PHP script, and I also have a program written in
> >> >> Pascal,
> >> >> it's compiled in the native executable for whatever OS the server is
> >> >> running.
> >> >>
> >> >> I want to have the user input info and then send that info to the
> >> >> Pascal
> >> >> program to call a function and send the info as parameters.
> >> >>
> >> >> Is there any sort of server side call I can do to do this? Or is my
> >> >> only
> >> >> option making some sort of connection such as SOAP between PHP and the
> >> >> Program?
> >> >>
> >> >> --
> >> >> PHP General Mailing List (http://www.php.net/)
> >> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >> >>
> >> >>
> >> >
> >> > RTFM for exec(), system(), passthru(), et cetera.
> >> >
> >> > <?
> >> > exec('pascal-file '.$_POST['user_command'],$ret);
> >> > $ret == 1 ? 'Error detected' ? '';
> >> > ?>
> >> >
> >> >
> >> > --
> >> > Daniel P. Brown
> >> > [office] (570-) 587-7080 Ext. 272
> >> > [mobile] (570-) 766-8107
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>

> >
> > Yeah, the first parameter of each function, where you call the
> > executable directly, just has to include the parameters you want to
> > pass to the binary.
> >
> > For example, if you wanted to do the following:
> > netstat -pnt
> > ls -al|grep -i php
> > mv file1.php backups/file2.php
> >
> > You would (respectively) simply do the following:
> > exec('netstat -pnt',$ret);
> > exec('ls -al|grep -i php',$ret);
> > exec('mv file1.php backups/file2.php',$ret);
> >
> > Then just eval $ret to see if it was successful (0) or not (1).
> >
> > If you wanted to allow a user to specify parameters, it would be
> > done like so:
> >
> > [php]
> > L> File: form.php
> > <?
> > if($_POST['parameters']) {
> > exec('/path/to/pascal-binary
> > '.escapeshellarg($_POST['parameters']),$ret);
> > $ret == 0 ? "Success!" : "Failure!";
> > exit;
> > }
> > ?>
> > <FORM METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF;?>">
> > Parameters: <INPUT TYPE="TEXT" NAME="parameters"><BR />
> > <INPUT TYPE="SUBMIT" VALUE="Process Now">
> > </FORM>
> >
> > --
> > Daniel P. Brown
> > [office] (570-) 587-7080 Ext. 272
> > [mobile] (570-) 766-8107

>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


If you can run the executable as a server, you could daemonize it....
<? exec('pascal-binary & 2>&1',$ret); ?>

.... and then connect to it using sockets.... but I'm not
completely certain that I'm understanding your needs properly.

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Reply With Quote
  #9 (permalink)  
Old 06-16-2007
Dan
 
Posts: n/a
Default Re: [PHP] Calling an executable for processing some data sent from PHP

Thanks for your help. Since it's a Delphi program and Delphi has the
ability to build ISAPI applications I'm going to try and see if I can't turn
my app into an ISAPI and run that since it has all the functionality I need
and it'll run fast. But if that doesn't work out I'll try the solutions
suggested. Yes daemonizing it would probably work too.

- Daniel


""Daniel Brown"" <parasane@gmail.com> wrote in message
news:ab5568160706151415i4192f735h98a4e60061caf1a7@ mail.gmail.com...
> On 6/15/07, Dan <frozendice@gmail.com> wrote:
>> Wow, thanks for the code and the fast response! :) Although maybe I
>> should
>> clarify my probem a bit more, I'm trying to run a program, but I want it
>> to
>> stay open so that I can call functions later.
>>
>> When the user "opens" a file, it's uploaded to a folder where PHP can
>> access
>> it, then PHP would call the Pascal program which would parse the file,
>> and
>> create a new object for that data, which later functions would access and
>> do
>> computation on. Like a user woud click Compute Subsets and that would
>> somehow trigger the function Compute_Subsets on that object. Any way I
>> could do something like this?
>>
>> My ugly way to do it would be to do an exec() to call an executable to
>> parse
>> the file and make an object of it then run the function that I needed to
>> every time a function was called. The code base for this would be
>> horrible
>> to maintain and incredibly slow.
>>
>> Is there some way I could keep the program open and give it further
>> arguments?
>> ""Daniel Brown"" <parasane@gmail.com> wrote in message
>> news:ab5568160706151352l7f0c002ah700d712088e90115@ mail.gmail.com...
>> > On 6/15/07, Dan <frozendice@gmail.com> wrote:
>> >> Will that script also work on Apache in Windows? OS X? Just checking
>> >> because the backend and front end both need to be able to be installed
>> >> on
>> >> any OS.
>> >>
>> >> Also I looked at exec(), system(), and passthru(); they all let you
>> >> execute
>> >> a executable file but I don't see any way of passing parameters in any
>> >> of
>> >> those functions, can you do that?
>> >>
>> >> - Daniel
>> >>
>> >> ""Daniel Brown"" <parasane@gmail.com> wrote in message
>> >> news:ab5568160706151311m3327bbccha02e3f5ca96255d8@ mail.gmail.com...
>> >> > On 6/15/07, Dan <frozendice@gmail.com> wrote:
>> >> >> Ok, so I have a PHP script, and I also have a program written in
>> >> >> Pascal,
>> >> >> it's compiled in the native executable for whatever OS the server
>> >> >> is
>> >> >> running.
>> >> >>
>> >> >> I want to have the user input info and then send that info to the
>> >> >> Pascal
>> >> >> program to call a function and send the info as parameters.
>> >> >>
>> >> >> Is there any sort of server side call I can do to do this? Or is
>> >> >> my
>> >> >> only
>> >> >> option making some sort of connection such as SOAP between PHP and
>> >> >> the
>> >> >> Program?
>> >> >>
>> >> >> --
>> >> >> PHP General Mailing List (http://www.php.net/)
>> >> >> To unsubscribe, visit: http://www.php.net/unsub.php
>> >> >>
>> >> >>
>> >> >
>> >> > RTFM for exec(), system(), passthru(), et cetera.
>> >> >
>> >> > <?
>> >> > exec('pascal-file '.$_POST['user_command'],$ret);
>> >> > $ret == 1 ? 'Error detected' ? '';
>> >> > ?>
>> >> >
>> >> >
>> >> > --
>> >> > Daniel P. Brown
>> >> > [office] (570-) 587-7080 Ext. 272
>> >> > [mobile] (570-) 766-8107
>> >>
>> >> --
>> >> PHP General Mailing List (http://www.php.net/)
>> >> To unsubscribe, visit: http://www.php.net/unsub.php
>> >>
>> >>
>> >
>> > Yeah, the first parameter of each function, where you call the
>> > executable directly, just has to include the parameters you want to
>> > pass to the binary.
>> >
>> > For example, if you wanted to do the following:
>> > netstat -pnt
>> > ls -al|grep -i php
>> > mv file1.php backups/file2.php
>> >
>> > You would (respectively) simply do the following:
>> > exec('netstat -pnt',$ret);
>> > exec('ls -al|grep -i php',$ret);
>> > exec('mv file1.php backups/file2.php',$ret);
>> >
>> > Then just eval $ret to see if it was successful (0) or not (1).
>> >
>> > If you wanted to allow a user to specify parameters, it would be
>> > done like so:
>> >
>> > [php]
>> > L> File: form.php
>> > <?
>> > if($_POST['parameters']) {
>> > exec('/path/to/pascal-binary
>> > '.escapeshellarg($_POST['parameters']),$ret);
>> > $ret == 0 ? "Success!" : "Failure!";
>> > exit;
>> > }
>> > ?>
>> > <FORM METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF;?>">
>> > Parameters: <INPUT TYPE="TEXT" NAME="parameters"><BR />
>> > <INPUT TYPE="SUBMIT" VALUE="Process Now">
>> > </FORM>
>> >
>> > --
>> > Daniel P. Brown
>> > [office] (570-) 587-7080 Ext. 272
>> > [mobile] (570-) 766-8107

>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>

>
> If you can run the executable as a server, you could daemonize it....
> <? exec('pascal-binary & 2>&1',$ret); ?>
>
> .... and then connect to it using sockets.... but I'm not
> completely certain that I'm understanding your needs properly.
>
> --
> Daniel P. Brown
> [office] (570-) 587-7080 Ext. 272
> [mobile] (570-) 766-8107

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:36 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0