Skip to content

Instantly share code, notes, and snippets.

@charliepark
Created October 3, 2019 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charliepark/e2133928703c1d2ce87259d2bc207fea to your computer and use it in GitHub Desktop.
Save charliepark/e2133928703c1d2ce87259d2bc207fea to your computer and use it in GitHub Desktop.
<?PHP
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";
echo("$time_log_message_1<br>$time_log_message_2");
shell_exec(": > messages1.txt");
shell_exec(": > messages2.txt");
@charliepark
Copy link
Author

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