Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80531

Re: Communicating with a PHP script (and pretending I'm a browser)

References <CACwCsY46yYFQwdYdriTSYSvLYF=xs6L2zanN9gofkWkoHvj_fA@mail.gmail.com>
From Marc Aymerich <glicerinu@gmail.com>
Date 2014-11-11 17:00 +0100
Subject Re: Communicating with a PHP script (and pretending I'm a browser)
Newsgroups comp.lang.python
Message-ID <mailman.15669.1415721637.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Nov 11, 2014 at 4:48 PM, Larry Martell <larry.martell@gmail.com> wrote:
>
> I have a PHP app that I want to convert to django. But I want to do it
> stages. All the heavy lifting is in the PHP code, so first, I want to
> just use templates and views to generate the HTML, but still call the
> PHP code. Then later convert the PHP to python.
>
> My issue is that the PHP code expects to get all it's input from the
> REQUEST object and I've consumed that in the view. Is there any way I
> can somehow supply that to the PHP code?
>
> Is there some way python can communicate like curl ... it needs to
> send the request string in the body of a POST request to the URL that
> will route to the PHP script and get the output back.


Yes,
I supose you can extract the needed information from the django
Request object and call the php script passing the needed variables as
environment state.

as a guideline you can do something like

cmd = (
    'REDIRECT_STATUS=200 '
    'REQUEST_METHOD=GET '
    'SCRIPT_FILENAME=htdocs/index.php '
    'SCRIPT_NAME=/index.php '
    'PATH_INFO=/ '
    'SERVER_NAME=site.tld '
    'SERVER_PROTOCOL=HTTP/1.1 '
    'REQUEST_URI=/nl/page '
    'HTTP_HOST=site.tld '
    '/usr/bin/php-cgi'
)
subprocess.Popen(cmd, stdout=subprocess.PIPE)



-- 
Marc

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Communicating with a PHP script (and pretending I'm a browser) Marc Aymerich <glicerinu@gmail.com> - 2014-11-11 17:00 +0100

csiph-web