1

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.

Alex Waygood
  • 6,304
  • 3
  • 24
  • 46
shyam
  • 21
  • 2

2 Answers2

0

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.

rob
  • 36,896
  • 2
  • 55
  • 65
-1

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...

CommunistPancake
  • 597
  • 2
  • 10
  • 22
  • Both the files are local file. Can explain your answer more clearly. – shyam Jun 30 '11 at 06:31
  • Is python script intended to run as a scheduled job and do something about those variables (e.g. write values in the file and read it from python?) or perhaps python should react in case php spits some output (e.g. pipe the output and use sys.stdin in python)? The question is a bit vague you have to admit. Could you edit it slightly to avoid a forum instead of question - answer scenario please? – Damian Jun 30 '11 at 08:09
  • @damian thanx for ur time... yeah admit quest is vague as i dont know what exactly u need here to find the way out(i m new to php and python) I just need to find the value of a particular variable. so it is readonly. i need to use the value in my python file.There is no need to edit the php file. – shyam Jun 30 '11 at 09:06