Функции по работе с файлами php вместо встроенных

На основе большого опыта работы с движком HumanEmulator, обратил внимание, что можно повысить отказоустойчивость, если не использовать функций работы с файлами, такие как: $textfile и $file_os . Это связанно с тем, что HumanEmulator принимает команды, как запросы серверу, соответственно большой поток таких команд может привести к критическим ошибкам в работе приложения, также наблюдается небольшой прирост к скорости исполнения.   Ниже представлен альтернативный список методов.


//Получить размер фала в байтах
$file_size = $file_os->get_size("res\\text.txt");

//Альтернатива
$file_size = filesize ("res\\text.txt");

//Получить число строчек в файле
$lines_count = $textfile->get_lines_count("data\\text.txt");

//Альтернатива
$lines_count = get_lines_count("data\\text.txt");

// Создание/Перезапись файла и запись в него текста
$textfile->write_file($file_path,$text,60);

//Альтернатива
file_put_contents($file_path, $text);

// Добавить текст в конец файла
$textfile->add_string_to_file("res\\file.txt", $text, 60) ;

//Альтернатива
file_put_contents($file, $str, FILE_APPEND | LOCK_EX);

//Проверить существование файла
if($file_os->is_exist("res\\text.txt")){
}

//Альтернатива
if(file_exists("res\\text.txt")){}

//Удалить файл
$file_os->delete("res\\text.txt"))

//Альтернатива
unlink("res\\text.txt");

//Заменить строки в файле на другое значение
$textfile->replace_string("data\\text.txt", "data\\text.txt", $old_value, $new_value, 60);

//Альтернатива (для одного и того же файла)
//read the entire string
$str=file_get_contents($file);

//replace something in the file string - this is a VERY simple example
$str=str_replace($oldValue, $newValue, $str);

//write the entire string
file_put_contents($file, $str);

//Получить n строчку из файла
$val = $textfile->get_line_from_file("data\\text.txt", false, $n, 60);

//Альтернатива
function get_line_from_file($file, $line_num, $delimiter="\n")
{
/*** set the counter to Zero ***/
$i = 0;

/*** open the file for reading ***/
$fp = fopen( $file, 'r' );

/*** loop over the file pointer ***/
while ( !feof ( $fp) )
{
/*** read the line into a buffer ***/
$buffer = stream_get_line( $fp, 9999, $delimiter );
/*** if we are at the right line number ***/
if( $i == $line_num )
{
/*** return the line that is currently in the buffer ***/
return rtrim($buffer);
}
/*** increment the line counter ***/
$i++;
/*** clear the buffer ***/
$buffer = '';
}
return false;
}

Список UserAgent ( UserAgent list)

//Код для получения 0 линии в файле
//Code for get 0 line number from target file
$user_agent= $textfile->get_line_from_file("data\\useragents.txt", false, 0, 60);

// Код для установки браузеру UserAgent в HumanEmulator
// Code for set UserAgent ащк IE in HumanEmulator
$browser->set_user_agent($user_agent);

Файл useragents.txt содержит список проверенных UserAgent ов
File useragents.txt contains list valid UserAgent s

Google drive