PHP run python code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
izzakh
Forum Newbie
Posts: 3
Joined: Tue Jun 16, 2015 5:09 am

PHP run python code

Post by izzakh »

hi there.. im having this python scripts snippet:

import webbrowser

url = 'http://idiotinside.com'

# Open URL in new browser window
webbrowser.open_new(url) # opens in default browser

# Opens in mozila browser
webbrowser.get('firefox').open_new_tab(url)



and PHP code to execute the python:
exec('C:\Python27\python.exe C:\xampp\htdocs\wd\launch_ff.py');

but it seems firefox is not launched.

Need help!!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP run python code

Post by Christopher »

Where do you expect it to launch Firefox? PHP runs on the server, so it will open a process and run Firefox there and then terminate the process.
(#10850)
izzakh
Forum Newbie
Posts: 3
Joined: Tue Jun 16, 2015 5:09 am

Re: PHP run python code

Post by izzakh »

i want to launch Firefox in my local after execute the script. is that possible?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP run python code

Post by Christopher »

You can run Firefox on the server, but it is run by the web server process. And Firefox should exit when the script exits. What is it you are trying to do?

You want to launch Firefox from a web page? How about:

<a href="mypage.php" target="_blank">Open Firefox</a>
(#10850)
izzakh
Forum Newbie
Posts: 3
Joined: Tue Jun 16, 2015 5:09 am

Re: PHP run python code

Post by izzakh »

Here is what my code is working:
1. launch firefox with urls taken from database..there will be multiple windows of firefox browser once the code is executed.
2. Firefox will exit once all url are loaded.

The objective of launching url into browser is for firebug add-on in the browser to analyse the url page.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP run python code

Post by Christopher »

Why not just use Javascript to open a window?
(#10850)
Post Reply