4

Background

I am considering various architecture options. While I have used SQL over the years as a query language, I have limited experience with triggers and stored procedures.

The Problem: Integrating PHP and Python via MySQL

In the red corner of the boxing ring, I have some off-the-shelf PHP which processes some XML pushed to the server via HTTP, and records it into a MySQL database.

In the blue corner of the ring, I have a daemon written in Python, that is keen to promptly learn of the data that has been pushed, so it can process it, in real time.

The boxing ring itself is Ubuntu (and probably Apache, but not yet confirmed).

Possible Solutions

I am considering three different ways of communicating between the processes.

  1. Totally rewrite the PHP to Python. Probably will take too long to be viable.

  2. Patch the PHP to have it also write the XML to a socket. Have a Python thread listening to the socket. This seems feasible. It will need to be rewritten every time a new version of the PHP is released. It also seems a little ugly.

  3. Write an SQL trigger that informs the Python code that the database has been updated, and it can fetch the latest through normal SQL queries. This is a technology I am not familiar with, and hence this question:

The Question

Is there a standard idiom for notifying a running Python program that another process has updated a MySQL table?

Possible Answers?

I assume the answer will include MySQL Triggers, but I am happy to be told I am barking up the wrong tree.

From my research so far, I believe one answer would be to trigger the execution of an arbitrary executable which could then talk via a socket to the main process, but I was hoping there might be something a little more direct - like a call to the SQL API that blocks until a trigger is fired.

1 Answer 1

2

Solution 4: Let Python publish a webservice (XMLRPC or SOAP) containing a webmethod that can be called by PHP to tell Python that new data is available.

(Python XMLRPC is very ease to use)

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent. This is very similar in principle to Solution 2, but provides a lot of the marshalling of the data over the socket for me. Definitely an improvement. Will investigate further. Still interested if I can avoid hacking the PHP (i.e. SQL triggers) though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.