Miscellaneous > The Lounge

Amazing PHP scripts!

(1/1)

reactosguy:
Here's a PHP script to create a really big CSV file! It's really impressive!



--- Code: ---
<?php
// Filename: spamtable_csv.php
$content = '"'.rand().'","'.date("Y-m-d").'","'.date("H:i:s").'"\n';
$fh = fopen("spamtable.csv","a");
while(file_exists("spamtable.csv"))
{
fwrite($fh,$content);
}
?>

--- End code ---


I used it 4 times to create a 154 MB CSV file that took like 8 minutes to open on my PC.


Here's a MySQL version:



--- Code: ---
<?php
// Filename: spamtable_sql.php
$rand = rand();
$date = date("Y-m-d");
$time = date("H:i:s");
$cxn = mysqli_connect("localhost","username","password","database");
$sql = "INSERT INTO spamtable (rand,date,time) VALUES ('$rand','$date','$time')";
$result = mysqli_query($cxn,$sql);
include("spamtable_sql.php");
?>

--- End code ---


The CSV edition is prone to unnecessary duplicates, and on Windows, no \n turning into the press of an enter/return button. I attempt to use this to prevent duplicates, but it won't fix Windows's dislike of the \n. I haven't tried this, it was a last minute addition.




--- Code: ---
<?php
// Filename: spamtable_csv.php
$content = '"'.rand().'","'.date("Y-m-d").'","'.date("H:i:s").'"\n';
$fh = fopen("spamtable.csv","a");
fwrite($fh,$content);
include("spamtable_csv.php");
?>

--- End code ---


Please be aware that MySQL server may get corrupted with a 20,000+ row table, requiring a drop of the junk table and probably a restart of the computer.


Have fun with this!

Aloone_Jonez:
If it's Windows, I think a batch file is the easiest way to do this.


--- Code: ---@echo off
echo Really big file>> bigfile.txt
:larger
 type bigfile.txt>> bigfile.txt
goto larger
--- End code ---

Navigation

[0] Message Index

Go to full version