jaymc Posted April 3, 2009 Share Posted April 3, 2009 Can anyone give me any pointers as to why I am getting segmentation faults when I run this It usually dies between 10,000 - 20,000 loops I have ruled out it being include ("/home/jay/funcs/random_password.php"); or include ("/home/jay/includes/mysqlpass.php"); <? include ("/home/jay/funcs/random_password.php"); include ("/home/jay/includes/mysqlpass.php"); // #################### // GENERATOR PASSWORD # // #################### function mp_password_generator($username, $amount) { $keywords = array(150 => 'chill',300 => 'cool',500 => 'boss',1000 => 'enjoy',1500 => 'respect',2000 => 'bonus',2500 => 'power',3000 => 'loaded'); $campaign = $keywords[$amount]; $cashamount = $amount / 100; $password = random_password(9); $insert = "INSERT INTO mp_passwords_copy SET `password` = '$password', `username` = '$username', `status` = '0', `number` = '0', `rc` = '$campaign', `owner` = '$username', `referer` = '$username', `transID` = '0', `currency` = 'GBP', `transType` = 'SYSTEM', `amount` = '$cashamount', `date` = NOW()"; mysql_query($insert) or die(mysql_error()); if (mysql_affected_rows() == "0") {echo "$password\nNoooooo";} if (mysql_affected_rows() == "1") {mp_password_generator($username, $amount);} mp_password_generator($username, $amount); } while($i < 100000){ $i++; mp_password_generator("jay", 300); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152408-solved-php-segfault/ Share on other sites More sharing options...
premiso Posted April 3, 2009 Share Posted April 3, 2009 In the php.ini (or where the extension information is listed) locate a line that has php_recode.dll (for windows) or recode.so (for *nix). If it does not have a ; infront, add one in, restart apache and see if that fixes the error. This information was found via Google at: http://daemon80.blogspot.com/2007/10/solved-php-segmentation-fault.html I am unsure if that is related to your problem, or if you tried it. As for me, I never heard of a segment fault error. Quote Link to comment https://forums.phpfreaks.com/topic/152408-solved-php-segfault/#findComment-800393 Share on other sites More sharing options...
jaymc Posted April 3, 2009 Author Share Posted April 3, 2009 There is no recode.so in my ini file Quote Link to comment https://forums.phpfreaks.com/topic/152408-solved-php-segfault/#findComment-800401 Share on other sites More sharing options...
premiso Posted April 3, 2009 Share Posted April 3, 2009 Run a phpinfo and post the contents in a quote or code tags here. EDIT: Reading up more on segfaults here http://wiki.gnokii.org/index.php/Segfault It sounds like the loop is eating up a lot of memory and has to resort to accessing reserved memory. 10,000 rows of SQL statements is a lot of rows, perhaps you can try to just make it the 10,000 and use session to spread it across multiple page reloads to accomplish. You can also maybe try increasing PHP's memory limit, but I doubt that would do. By chance how much RAM does your server have? EDIT EDIT: It looks like you have an infinite loop in your code. if (mysql_affected_rows() == "0") {echo "$password\nNoooooo";} if (mysql_affected_rows() == "1") {mp_password_generator($username, $amount);} mp_password_generator($username, $amount); You re-call the function there while inside the function. This just keeps calling the function, my bet is, that is your issue. Infinite loop. Quote Link to comment https://forums.phpfreaks.com/topic/152408-solved-php-segfault/#findComment-800408 Share on other sites More sharing options...
jaymc Posted April 4, 2009 Author Share Posted April 4, 2009 It looks like you have an infinite loop in your code. if (mysql_affected_rows() == "0") {echo "$password\nNoooooo";} if (mysql_affected_rows() == "1") {mp_password_generator($username, $amount);} mp_password_generator($username, $amount); You re-call the function there while inside the function. This just keeps calling the function, my bet is, that is your issue. Infinite loop. I have edited that bit out and just called the function 100,000 times like this while($i < 100000){ $i++; mp_password_generator("jay", 300); } It still segfaults Quote Link to comment https://forums.phpfreaks.com/topic/152408-solved-php-segfault/#findComment-801257 Share on other sites More sharing options...
jaymc Posted April 4, 2009 Author Share Posted April 4, 2009 Ah ok, calling mysql_affected_rows twice was the problem if (mysql_affected_rows() == "0") {echo "$password\nNoooooo";} if (mysql_affected_rows() == "1") {mp_password_generator($username, $amount);} Cheers Quote Link to comment https://forums.phpfreaks.com/topic/152408-solved-php-segfault/#findComment-801265 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.