Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print Python output by PHP Code

I have a scraper which scrape one site (Written in python). While scraping the site, that print lines which are about to write in CSV. Scraper has been written in Python and now I want to execute it via PHP code. My question is

how can I print each line which is getting printed by python code.

I have used exec function but it is none of my use and gives output after executing all the program. So;

Is it possible to get python output printed while it is getting executed via PHP.

like image 657
Rajiv Pingale Avatar asked Dec 09 '12 11:12

Rajiv Pingale


1 Answers

If i understand it well, your python scraper output to a file and you want to "live" display the output via php. What about doing and loop in php in which you use filemtime to know whether or not the file has been updated? You might add a little sleep in order not to overload your server.

If your are using a web page, you may use AJAX to reload only the concerned part of the page at a regular interval.

Hoping this helps you.

like image 153
martinqt Avatar answered Sep 22 '22 06:09

martinqt