I have a python script (on Windows Server) that requests information through an API, downloads data into several csv and at the end it 'zips' them all into 1 single .zip file. The idea is to access that zip file through an URL, using PHP.
But the main issue here is PHP making the zip available, even before the file is not yet completely compressed.
Using the 'sleep' function, I believe will halt the execution of PHP, even the Python script, am I right?
My current setting is using a Task, on Windows Task Scheduler, to trigger the Python script, download the necessary files and only then, making the zip file available with PHP.
Is there any way of doing all the process within PHP script, without using Windows Task Scheduler?
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . "/#classes/simple_html_dom.php";
#header("Content-type: text/html");
header("Content-Disposition: attachment; filename=api-week-values.zip");
unlink("api-week-values.zip");
$command = escapeshellcmd('python api_weekly.py');
$output = shell_exec($command);
sleep(15);
?>
You can see the code I am using for the whole process.
To clarify the process:
- An application needs to access the file I am downloading with the python script
- I feed the application with the URL from Apache server
- the application goes to the link (through index.php) and triggers the python script (which downloads the zip file)
- php should pop-up a save file WHEN the zip file has been completely downloaded