C
C
Chvalov2015-11-27 15:50:44
PHP
Chvalov, 2015-11-27 15:50:44

Is it possible to fix the php script in this way to download the file?

There is a script

$url = 'http://site.ru/down/file.php'; // URL откуда будем выкачивать
$save_path = __DIR__;  // Куда будем складывать файлы
$start = microtime(true);  //запуск таймера

for($i=0;$i<=999999;$i++){ // Индетификатор файлов от и до
  file_put_contents($save_path.'/'."file_{$i}.png",file_get_contents($url."?id={$i}"));
}

echo 'Время выполнения скрипта: '.(microtime(true) - $start).' сек.'; //вывели время выполнения

1) I would like to get the name and type of the file using the basename function and then check whether the file exists and if it exists then skip it.
And if basename does not return a name, then use its id as the filename
2) Limit the number of threads if possible
3) Pause, otherwise with a large number of files, PHP just stops due to lack of execution time, you have to edit php.ini, but I would like to fix this at the level of the script itself

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-11-27
@alexey-m-ukolov

1) I would like to get the name and type of the file using the basename function and then check whether the file exists and if it exists then skip it.
And if basename does not return a name then use its id as the filename
Can.
2) Make the number of threads limited if possible
Can.
3) Pause, otherwise with a large number of files, PHP just stops due to lack of execution time, you have to edit php.ini, but I would like to fix this at the level of the script itself
Can.
And if you expect that the code will be written for you here, I have bad news for you ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question