1

I have a running python application that needs to receive some data and process them. and I also have a PHP server that can get these data. I want to send JSON data from PHP to my python app. anyway except running a python web server and send data to it, or insert into DB and get from DB with python? thanks.

I tried using python cherryPy web server.

2
  • hello NiklasD welcome to stackoverflow check out this link this should help you Commented Jan 1, 2019 at 21:42
  • Assuming that speed is a critical concern, you could just write into temporary files that both processes have access to, and then watch the file contents on each end. Commented Jan 1, 2019 at 21:53

2 Answers 2

1

@Niklas D It would be easier to answer your question, if you can give some more context about the application or use case you want to solve.

Some further possibilities are:

Glue Code (I never did it with python and php only C++ with python, but you should be able to find examples on the internet e.g. https://wiki.python.org/moin/IntegratingPythonWithOtherLanguages#PHP )

Messaging Systems like RabbitMQ, ActiveMQ, ZeroMQ, etc.

Redis (I know you said except writing to a database, but Redis provides some features for publish subscribe https://redis.io/commands/pubsub which allows you to write to Redis from the one side and get data on the other side without polling the db all the time, which is the issue you have with using a database I guess) It's a bit easier to setup and use, than a messaging system.

TCP connection between the python and php application. https://medium.com/swlh/lets-write-a-chat-app-in-python-f6783a9ac170

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

1 Comment

actually, I have an assistant program that takes orders, when I said except inserting and selecting from DB that because my python DB checker must have to run every second or so, I use artyom.js for translating speech to text and it requires a PHP server for working well, now I want to send these text orders from PHP to python. python offline speech to texts are so bad and I couldn't find online free API for that. thanks.
0

If you want to send data to a python application using web protocols, i.e send POST, GET requests etc then you need to create a python web app to receive and handle those requests. Which in turn needs to be running off a webserver or you could build serverless functions to handle this, see https://serverless.com/

If you want to get data using a python application, i.e the python app sends POST and GET requests etc to your php app to ask for the JSON payload you can build an app using python's standard requests library https://docs.python.org/3/library/urllib.request.html or better still us the Requests package http://docs.python-requests.org/en/master/

Or you could do something and save the JSON file to disk and then open it with your python app. You'd need to set up scheduling or make your php app execute python code on the server... This last suggestion is a bad idea please don't unless your app is isolated and not publicly accessible or you know how to lock down your security.

2 Comments

Would you mind elaborating on why a temporary file is a "silly" solution?
That's my bad @Aleon. It actually might not, I shouldn't have called it silly, really depends on the context. I conflated it with the shell execute option in my mind, which I don't think is a good idea unless the web apps arent't exposed to the public or the creater has an advanced knowledge of server security.

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.