N
N
Newn2018-04-19 14:35:16
PHP
Newn, 2018-04-19 14:35:16

Is there a txt file in php, if not, then we are waiting for it to appear?

Do not judge strictly. There is a txt file in php, if not, then we are waiting for it to appear? How to implement it in php?

$file = 'exchange_id_1.txt';
if(file_exists($file))
{
//Файл есть, обработали.Вывели
}
else
{
//Файла нет, ждем пока появится. 
}

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ildar Saribzhanov, 2018-04-19
@Newn

function processing_file($file_path)
{
  if ( ! file_exists($file_path)) {
    // Засыпаем на 5 секунд
    sleep(5);
    
    // рекурсивно вызываем функцию
    processing_file($file_path);
  }
  
  // Обработка файла
}

Y
Yan-s, 2018-04-19
@Yan-s

while(!file_exists($file)) {
    sleep(5); // файла нет, ждем 5 сек, повторяем заново
}
// файл появился, работаем.

P
Pavel, 2018-04-19
@PavelMonro

Through timeout

function est_li_file($vashfile, $timeout) {
      ini_set('default_socket_timeout', $timeout);
      stream_set_timeout($timeout); 
      $vashfile = fopen($vashfile, 'r');
      if($vashfile) {
          fclose($vashfile);
       ваш код
     }else{
          ваш код когда отсутствует
     }
   }

A
Andrey Lezhnin, 2018-04-19
@ALejnin

How should he appear? Do you need to create a script? Someone creates files by hand? Magic ala "vzhuh and the file appeared"?
file_put_contents() & fopen()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question