tags:

views:

174

answers:

3

What is the best way to communicate with another process in PHP?

Update: Using Windows, PHP 5, calling COM assemblies, COM may or may not be needed, I don't really care.

Update: I am trying to send a command from PHP to Ascom (a control program). I mainly need to execute methods and pass small parameters. I also need to be able to get information from it.

A: 

What kind of interfaces does ASCOM come with? Did a google search but did find several programs.

henchman
ASCOM is a device independent COM driver for astronomical equipement.
Byron Whitlock
+2  A: 

Your best bet will probably be to write a wrapper that wraps the com assembly using C# or C++. The simplest way to use it would be command line based.

ASCOM.exe focuser position would yeild the position of the focuser.

ASCOM.exe focuser move 25 would move the focuser but wouldn't return until it has been moved.

Make sure that you are taking care of multi-user issues with this! If you have 10 people trying to move the instrument around you will have problems.

Edit

In php you make calls to external commands with the system() or exec() command. You should use system() because it blocks until the command completes.

$pos = system("ASCOM.exe focuser position"); Would put the position in the $posvariable. Remember ASCOM.exe is a program you have created to take these command line args and convert them into the appropriate COM calls.

Read this MS article on making a COM wrapper in C#. If you prefer to use C++, try this article. Finally, if you are uncomfortable in either of those languages, you can access COM objects in powershell easily.

Byron Whitlock
How do I get it to return the position?
Arlen Beiler
In fact, how do I call it from PHP?
Arlen Beiler
How do I make a program return something?
Arlen Beiler
+3  A: 

I use COM quite extensively with PHP, using COM objects built in C++ from our library, with Apache as the web server, on Windows 2003. It has worked pretty well for about five years.

You can instantiate and use a COM object directly in PHP. Looking at the Ascom camera interface given here http://ascom-standards.org/Standards/Index.htm, I would expect it to work fine; something like this:

      $camera = new COM('ManufacturerName.Camera'); // COM class name made up
      $camera.NumX = 200;
      $camera.NumY = 200;
      $camera.BinX = 1;
      // Set more properties... then, having set $duration and $light:
      $camera.StartExposure( $duration, $light );
      // etc

ie you can use properties and methods just how you would expect. The actual COM class name will be in the docs of your instrument. You may find it in any example code the manufacturer has given you.

If you are using it in a web process, be aware that you will have to re-instantiate the COM objects each time you service an HTTP request, and reconnect to the instrument.

Have a go - you will probably be pleasantly surprised by how straightforward it is.

willw