Jump to content

Generate users in bulk?


FuturShoc
 Share

Recommended Posts

I'm bootstrapping PW in order to import logins and passwords from an existing text file.
It's all working fine, but execution time is taking much longer than it really should. I'm only getting about 180 users generated before it times out. The file contains 1000 entries. (I've broken the original file of about 9000 entries down to 9 smaller files with 1000 entries each.)

Yes, I've adjusted my php.ini config to allow up to 180 seconds of execution time, but I'm hesitant to adjust higher since the server holds lots of other productional sites.

Is there a better way to generate users in bulk?


include("index.php");

$file = file_get_contents("myfile.txt");
$user_array = explode("\n", $file);

foreach ($user_array as $user) {

$uray = explode(",", $user);

$username = strtolower(trim(str_replace(array('@', '.', '_'), '-', $uray[0])));

$u = new User();
$u->name = $username.'xxx';
$u->email = trim($uray[0]);
$u->pass = $uray[1];
$u->addRole("parkhill-member");
$u->save();

}

echo 'Done.';

Link to comment
Share on other sites

You can set set_time_limit(30); within the foreach-loop.
 
That way you have higher settings only with that script, not with the whole server.

EDIT:

If you need for what ever reason a check you can do it at your own:

$start = time();
$maxallowed = 600;

foreach($somethings as $something) {
    // ... your code
    set_time_linit(10); // reset the countdown for every loop!
    if(time() > ($start + $maxallowed)) {  // check the max executed time of the script
        // break or exit or whatever
    }
}
Edited by horst
  • Like 2
Link to comment
Share on other sites

Hi FuturShoc,

I'd guess that it's hashing the passwords for each user you are adding that's causing the delay here as the hash function has to be deliberately slow to make brute-forcing a leaked hash harder.

hort's suggestion of calling set_time_limit(30); in the loop is definitely where I'd start addressing this.

Link to comment
Share on other sites

Wanze's suggestion is working great for me. And I was able to keep the max execution time on the server set to 30 seconds.



If you can't set the timeout higher, try to load this script from the command line.

The script timeout isn't a problem there, as far as I know.

Thanks, Wanze!

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...