Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
shell_exec("touch messages1.txt");
shell_exec("touch messages2.txt");
$time_1 = microtime(true);
for ($i=1; $i<1000; $i++) {
file_put_contents('messages1.txt', "This is the sample text\n", FILE_APPEND);
$time_delta_1 = microtime(true) - $time_1;
$time_log_message_1 = "$time_delta_1 delta for file_put_contents\n";
$time_2 = microtime(true);
for ($i=1; $i<1000; $i++) {
shell_exec("echo 'This is the sample text' >> messages2.txt");
$time_delta_2 = microtime(true) - $time_2;
$time_log_message_2 = "$time_delta_2 delta for shell_exec(echo)\n\n";
shell_exec(": > messages1.txt");
shell_exec(": > messages2.txt");
Copy link

charliepark commented Oct 3, 2019

Fairly standard output:

0.16222381591797 delta for file_put_contents
3.1839950084686 delta for shell_exec(echo)

So … use file_put_contents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment