tags:

views:

84

answers:

2

Hi guys!

I realize it's probably something strange, but here is what I have.

I have an application (handwriting recognition engine) written in C/C++. This application has Perl wrapper which was made by application's authors using SWIG. My website is written in PHP, so I'm looking for some ways to make PHP work with C/C++ application.

The only way I can think of now is to create a CGI script (perl script) which accepts POST request from my website (AJAX request), sends it to the recognition engine through it's Perl wrapper, gets the required data and returns the required data as a response to AJAX request.

Do you think it could be done this way? Are there any better solutions?

Thank you!

+2  A: 

Do you think it could be done this way?

Yes, no reason it can't be done.

Are there any better solutions?

May be. If you intend to execute the perl wrapper as a system call to a separate Perl script, you don't need a separate CGI perl script. You can just do system calls from PHP in your site directly. Not a big difference but might help if PHP is more of your comfort zone for web stuff than Perl's CGI

OTOH, if the Perl script wrapper is a fairly obvious and simple set of API calls, and you feel comfortable with Perl CGI, a better soltrion is to port that command line Perl script into the Perl CGI script which uses the API internally, bypassing system calls.

For high-volume stuff, removing system calls is a Big Win performance wise, plus allows for much better and easier error handling.

DVK
+2  A: 

What you are proposing is:

web client <-> Perl CGI script <-> Perl wrapper <-> C program

There is nothing particularly wrong with this approach, although it's clearly not the most efficient possible way to do it. How important is performance? If it's doesn't have to be amazingly fast, sure do it this way, which sounds like it's the easiest to develop.

If you want to go a step further, then the obvious point of optimization in the schematic above is to collapse the two Perl layers:

web client <-> Perl CGI script <-> C program

The question is, is it worth your time to do this? You can look at the source for the Perl wrapper and decide for yourself.

My advice would be to initially develop it the simple way and then if, for whatever reason, you decide it is insufficient, to merge the two Perl scripts into one. But for now, don't worry about it and go ahead with your idea.

RarrRarrRarr