0

I have this php script that imports each row to my database. After it saves, in the same process it will do some more stuff, takes 1-2 sec for each row so my user prefers to send the CSV file to me, then I run in the terminal.

I want to build a page to him, so he can drop the CSV in a file input, until here ok, I saw how to make this run in background, but I really want to show in the page the results of importing, my scripts echoes the result for each row in the CSV in the terminal. How to do something similar in the HTML?

How to make the user drops the CSV in a file input and see the result for each row right bellow as like he had executed the script in a terminal on his screen?

EDIT (making things clear)
I want to display the script messages while it's running, I mean, for each row of the csv file, my script will output/echo the result of the import, I want to immediately display this row result to the user in the HTML page. Not after the script execution finishes. Something like a stream.

Leo Cavalcante
  • 2,327
  • 2
  • 22
  • 30

1 Answers1

1

Sounds like you need to look at using jQuery and AJAX which will achieve what you're aiming for. This allows you to send data to a script, such as PHP, and the script processes in the background before sending the response.

Ashley
  • 1,459
  • 2
  • 12
  • 25
  • Ok, but, AJAX will make the request to start a background process and then die. I want to display to the user the outputs of the process. I'm thinking about logging the results to a file or queue and use long-polling ajax strategy to fetch these logs. Is this the best way? Also maybe will join an adventure thought NodeJS and SocketIO that will be basically the same ideia, logging/fetching but using proper technology (websockets) instead of long-polling. Maybe Redis to store the results. – Leo Cavalcante Nov 04 '15 at 17:36
  • The process can send output back to the code that made the AJAX call, there's no need to store it anywhere. – Ashley Nov 05 '15 at 11:25
  • My script does output messages, while its running. Can AJAX call read them? My `onSuccess` or `done()` callback won't be fired only when the script execution finishes and returns a response? – Leo Cavalcante Nov 05 '15 at 16:55
  • The answer to that can be viewed at http://stackoverflow.com/questions/3901495/what-is-the-best-way-of-showing-progress-on-an-ajax-call. Not a PHP example, but gives you the general gist. – Ashley Nov 06 '15 at 17:13