Q:

Python to POST data to local PHP on linux

This may sound a bit strange but I need this to happen like this for a reason. 
I need python to be able to post data to a local PHP file on a linux server and then get a response from the PHP. 
I have tried this:
p = subprocess. Popen("curl --data 'param1=value1&param2=value2' /home/hbmukwm/temp/receive.php", shell=True, stdout=subprocess. PIPE)
reply = p.stdout.read()

But when I do this, as it's a local file I get this curl error: curl: (3)  malformed
I also tried it this way (found on a stackoverflow answer)
mydata=[('one','1'),('two','2')]
mydata=urllib.urlencode(mydata)
path='file:/home/hbmukwm/temp/receive.php'
req=urllib2.Request(path, mydata)
req.add_header("Content-type", "application/x-www-form-urlencoded")
reply=urllib2.urlopen(req).read()

But in this case I get the php response as plain text like I'm just trying to read the PHP file, again I think this is happening because the PHP file is local, like this:
<? php echo "test"; ? >

Rather than just
test

Hope this is making sense so far.  All I need to do is POST the data to the local PHP file, and then get the PHP response back to python... Is this possible...
Any response is highly appreciated, sorry for my ignorance! 

A:

Thanks everyone for your responses, I have learnt something at least!  The reason I wanted to have it as a local file is because I didn't want the PHP files to be publicly accessible, though data needed to be sent to them from any location the application was run.  So my idea was to create a small python application that runs on a port on the linux server that takes commands and passes them to the PHP files local to the server. 
Anyway, the way I have got this working is by using a command line (Like my first example) except using:
p = subprocess. Popen("php /path/to/file 'data=this'", shell=True, stdout=subprocess. PIPE)

And then in the PHP files grabbing the argument like this
$data = $argv[1];

This isn't posting the data to the PHP files like I initially was asking for but I guess I mis-understood what I needed to do.  So thank you for all your help guys!  I can't really figure out which one of your answers was the definitive answer because you were all correct in what you said, but the answer I am posting now is how I overcome the problem. 
Thanks again guys, Stack Overflow  is the best :)

