1

I've a little code snippet here:

<?php
    //logic to connect to database and rest of the settings.
    // ...................//
    $res = mysql_query("select * from account");  //returns 1200 records
    while($row = mysql_fetch_array($res)){
        //some of the logical operations performed here.
        if(condition){  //condition is not a variable. its result to be evaluated
            updateDatabase($data1, $data2);
        }else{
            updateDatabase($data1, 0);
        }
    }
?>
<?php
    function updateDatabase($data1, $data2){
        //some logical operations
        //updating database.
        //for testing an echo statement whether success/fail
    }
?>

As this code retrieves thousands of records and operations to be performed on that and database need to be update in each case. But if I'm running this php file then its stops executing after reaching around 1000 records.

I'm unable to know the reason why it doing so as I'm beginner to php.
Anybody could help me with this problem?

5
  • No error in the PHP error log? Remove everything from your while loop. Add a counter. Now, how many times have iterated? Commented Jun 13, 2013 at 9:44
  • I've done that too. But the counter stops, not at a fixed number. Sometimes it stops at 900, 1050, 990 ... Commented Jun 13, 2013 at 9:46
  • There must be something in the error log. Please post a relevant excerpt. Commented Jun 13, 2013 at 9:47
  • where would I found error log? I'm newbie to php Commented Jun 13, 2013 at 9:50
  • The location of your error log is defined in your PHP configuration. In case of doubt, echo ini_get('error_log'); will tell you where it is. Commented Jun 13, 2013 at 10:03

1 Answer 1

2

try to increase the max_execution_time in your php.ini file. Maybe the script is running too long according to your php configuration.

Sign up to request clarification or add additional context in comments.

4 Comments

current value is 30. What should I make it to?
this means that scripts called by your server will stop after 30 seconds if they have not finished until then. Increase to 60 and try. If still stopping and not being finished you can increase further. If it is on a development machine, you can increase to 300 or more if you like, without having issues
thanks for your reply. Now it works. Can there be any better solution of doing such long tasks instead of making a php file and running it?
optimize your code or run jobs in background. You could execute a php commandline script to perform the task, which has no timeout by default and which priority could be decreased

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.