I’m working on a simple PHP based website
The basic structure is :
-
It takes some data as input via a web form, hands it over to some
shell scripts to process (via the system() function) -
The result of the processing is written to a .txt file
-
This file is then read by the script and displayed in the browser
It takes about 2-3 seconds to generate the .txt file after the handover is completed
Is there any correct way of making PHP wait for the file to be generated?
Currently I put the PHP script to sleep for 5 seconds and then read the file exists. This is obviously not a very good idea since each time the PHP script executes, it will take 5 seconds regardless of the time actually needed.
Runs on Apache on Ubuntu if thats relevant
Simple answer: Don’t use
system(), use exec() without redirecting to a file: