Stop Microsoft

Miscellaneous => The Lounge => Topic started by: reactosguy on 10 October 2010, 22:57

Title: Amazing PHP scripts!
Post by: reactosguy on 10 October 2010, 22:57
Here's a PHP script to create a really big CSV file! It's really impressive!


Code: [Select]

<?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);
}
?>



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: [Select]

<?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");
?>



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: [Select]

<?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");
?>



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!
Title: Re: Amazing PHP scripts!
Post by: Aloone_Jonez on 10 October 2010, 23:20
If it's Windows, I think a batch file is the easiest way to do this.

Code: [Select]
@echo off
echo Really big file>> bigfile.txt
:larger
 type bigfile.txt>> bigfile.txt
goto larger