Jump to content

Recommended Posts

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

?>

 

Link to comment
https://forums.phpfreaks.com/topic/152408-solved-php-segfault/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/152408-solved-php-segfault/#findComment-800393
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/152408-solved-php-segfault/#findComment-800408
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/152408-solved-php-segfault/#findComment-801257
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/152408-solved-php-segfault/#findComment-801265
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.