简体   繁体   中英

How to access variable values of a php script from a python script?

How can I access my php script from a Python script?

I need my Python script to be able to access the variables within the php script. (By the way, I'm new to php and Python.)

Thanks in advance.

I think this might be the answer to your question: Calling Python in PHP

More on the subject here (python) and here (php) .

If I understand it correctly, you have a service in PHP, and want to communicate with another one in Python.

Now, this is not really related to PHP or Python: this is quite a classic issue of integration and there are several ways to accomplish it; without more details about your problem, it may be very difficult to be specific about a solution and what kind of approach could be the better for you, but below you can find some ideas.

You could for instance save the status from PHP service in an ad-hoc table in the database, and then query it from the Python service.
Another way could be to use a RESTful approach: the information is available as a resource, accessible via a GET query; in PHP you would have a small handler that would just return a small JSON (or XML, if you like that kind of stuff), and in Python you would have instead the client. Of course, there are security issues to consider, but I think you got the idea.

For more information, I recommend you having a look at an interesting series written some time ago by Paul Stovell about integration. It is very accessible, and shows several approaches - although not all of them apply to your current issue.

Elaborate. Is the PHP file local? On a webserver? Where's the python file?

If the php file is on a server with the python file, use an exec statement. If the python file is local and the php file is on a server, then you need to use urllib. If both are local, write an interpreter...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM