Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a web application that uses jQuery (via ajax) to PHP and from there to a MySQL database. I need to do some ML using Python and reading from the database. My problem is that I am unable to figure out how to communicate from PHP to Python and back to PHP?

For more context, this will be a food recommendation system so on the website, if the user wants recommendations they can select filters (e.g. price range). Now at the moment, this will send a request to PHP and I am trying to pass data to Python run the recommender and get back to PHP with the returned data. Or is there a better way to do this? Like communicate from jquery to Python straight away. (I have Python running the recommender by itself communicating with the database, it just needs the filters that are in jquery)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
208 views
Welcome To Ask or Share your Answers For Others

1 Answer

You could use something like WebSockets to communicate from your front end to the Python backend. WebSockets are basically elevated HTTP sessions which allow for bidirectional transmission.

Mozilla docs have great information on WebSocket API that's built into modern browsers. Here

This would be if you wanted to communicate straight from the front-end to python. If you wanted to do it from the backend (php), you could establish a socket connection from php to your python program. (TCP). But this might a bit overkill.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...