FuturShoc Posted August 21, 2013 Share Posted August 21, 2013 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 More sharing options...
Wanze Posted August 21, 2013 Share Posted August 21, 2013 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. 2 Link to comment Share on other sites More sharing options...
horst Posted August 21, 2013 Share Posted August 21, 2013 (edited) 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 August 21, 2013 by horst 2 Link to comment Share on other sites More sharing options...
netcarver Posted August 21, 2013 Share Posted August 21, 2013 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 More sharing options...
FuturShoc Posted August 21, 2013 Author Share Posted August 21, 2013 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! 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now