Elixir application runs a PHP script

I’m writing an elixir application that needs to communicate with several APIs.

One api is a connection to Post Affiliate Pro which uses PHP and has a PHP class file you can download to use their API easily.

So my question is, How can I use Elixir to run a PHP script that I’ll need to write to communicate with the API?

I know nothing about PHP, I don’t even know what dependencies I’ll need on the server to run a php script.

My elixir program currently runs an executable using System.cmd(), maybe there’s a similar way to run a script? Anyone have any suggestions?

Of course you can run a php script as any other. If it has proper access rights and she bang you can run it directly, if not you need to run it through php executable.

What dependencies you need to install does depend on the class provided by your service partner. Also dependencies of php itself should be managed by your distros package management system.

But to be honest. Before doing such ugly stuff I’d ask for a proper documentation of their api and implement a client in elixir and release it on hex as well…


I’m guessing this is the API documentation for what @LegitStack is asking about. It seems like it would be a very complex task to adapt that PHP code to Elixir, and the documentation doesn’t exactly provide details on what URLs to make requests to.

Good luck, @LegitStack!


I understand that Ports (http://erlang.org/doc/reference_manual/ports.html) are a common way to handle communication with external processes. It seems that you should be able to write your PHP interop script so that it runs from a Port and uses the communication capabilities of that port to communicate through to your Elixir processes.


Take a look at http://github.com/alco/porcelain - it can be a good replacement for System.cmd.

1 Like