我有一个函数,.md每隔几分钟就会在 ~8000 个文件上写入 ~120Kb-150Kb 的 HTML 和元数据,并具有固定名称:a-agilent-technologies-healthcare-nyse-us-39d4
aa-alcoa-basic-materials-nyse-us-159
aaaau-perth-mint-physical-gold--nyse-us-8ed9
aaba-altaba-financial-services-nasdaq-us-26f5
aac-healthcare-nyse-us-e92
aaadr-advisorshares-dorsey-wright-adr--nyse-us-d842
aal-airlines-industrials-nasdaq-us-29eb如果文件不存在,它会很快生成/写入。然而,如果文件存在,它的执行速度会慢得多,因为现有文件携带约 150KB 数据。我该如何解决这个问题?我是否在同一目录中生成一个具有新名称的新文件,并在for循环中取消链接旧文件?还是我生成一个新文件夹并写入所有文件然后取消链接上一个目录?这种方法的问题是有时 90% 的文件被重写,有些保持不变。代码此函数正在for循环中调用,您可以在此链接中看到它public static function writeFinalStringOnDatabase($equity_symbol, $md_file_content, $no_extension_filename){ /** *@var is the MD file content with meta and entire HTML */ $md_file_content = $md_file_content . ConfigConstants::NEW_LINE . ConfigConstants::NEW_LINE; $dir = __DIR__ . ConfigConstants::DIR_FRONT_SYMBOLS_MD_FILES; // symbols front directory $new_filename = EQ::generateFileNameFromLeadingURL($no_extension_filename, $dir); if (file_exists($new_filename)) { if (is_writable($new_filename)) { file_put_contents($new_filename, $md_file_content); if (EQ::isLocalServer()) { echo $equity_symbol . " ? " . ConfigConstants::NEW_LINE; } } else { if (EQ::isLocalServer()) { echo $equity_symbol . " symbol MD file is not writable in " . __METHOD__ . " ? Maybe, check permissions!" . ConfigConstants::NEW_LINE; } } } else { $fh = fopen($new_filename, 'wb'); fwrite($fh, $md_file_content); fclose($fh); if (EQ::isLocalServer()) { echo $equity_symbol . " front md file does not exit in " . __METHOD__ . " It's writing on the database now ?" . ConfigConstants::NEW_LINE; } }}
1 回答
- 1 回答
- 0 关注
- 123 浏览
添加回答
举报
0/150
提交
取消