Skip to content

Instantly share code, notes, and snippets.

@ssigwart
Created January 30, 2015 03:20
Show Gist options
  • Save ssigwart/def32a5486da90813abd to your computer and use it in GitHub Desktop.
Save ssigwart/def32a5486da90813abd to your computer and use it in GitHub Desktop.
Redline13.com Custom PHP Load Test Downloading Credentials
<?php
/**
* This example is for writing a Custom PHP Load Test on redline13.com that might need to pick a random E-mail or other data.
* If placed inside of the CustomTest constructor, you can download a list of E-mails and randomly pick one to use for the test.
* The initial locking part ensures that the file is only downloaded once.
* This approach can be used to download other types of files that might be needed as well.
* For example, if you need to test uploading files, this can be used to download the files that you will be uploading in your test.
*/
// Are we the first to create the lock file?
if (($file = @fopen('filesetup.lock', 'x')))
{
fclose($file);
file_put_contents('emails.txt', file_get_contents('http://example.com/emails.txt'));
}
// Try several times to get an E-mail
$email = null;
for ($i = 0; $email == null && $i < 60; $i++)
{
// Pick a random E-mail
if (($file = fopen('emails.txt', 'r')))
{
$pos = rand(1, filesize('emails.txt') - 3);
fseek($file, $pos, SEEK_SET);
do
{
$pos--;
fseek($file, -1, SEEK_CUR);
$c = fgetc($file);
fseek($file, -1, SEEK_CUR);
} while ($pos > 0 && $c != "\n" && $c != "\r");
if ($pos !== 0)
fseek($file, 1, SEEK_CUR);
$email = trim(fgets($file));
fclose($file);
}
// Wait a little
else
usleep(250000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment