Lengthy Script and Calculation

Discussion in 'PHP' started by m_maheshwariin, Jun 20, 2009.

  1. #1
    Hello FRIENDS,

    I have problem with program output in php. What is my program is

    Input Values - A LENGTHY CALCULATION - OUTPUT

    I have to put values 10000 times. But php does not work after 3 or 4 values.

    Can somebody help me how can i control memory of php? and is it possible after putting 1 value program wait for output. and after output it take value after few moment?

    Does php buffer help?

    Plz i need a urgent help regarding this.

    Thanks
     
    m_maheshwariin, Jun 20, 2009 IP
  2. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #2
    why wouldnt your script out put multiple values? .. or do you mean processes involved and you dont want to hit the button everytime to submit it? It doesnt make sense .. because after your first value is submitted, why cant your PHP script use that to complete all the variables/ values?

    If you need somethin without page reload, use PHP and Ajax
     
    ezprint2008, Jun 20, 2009 IP
  3. m_maheshwariin

    m_maheshwariin Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I donnot have much knowledge about ajax..

    See, what exactly happen

    <?php

    $var = {Array has five hundred values} // extracted from database
    $title = {Array title of five hundred values} // extracted from database

    $count = count($var);

    for{$j=0;$j<$count;$j++)
    {
    $output_val = lengthy_function_calculation($var[$j]);
    }

    lengthy_function_calculation($id)
    {
    Length Calculation;
    return output;
    }

    ?>


    Now program get interrupt after 3 or 5 values passes.

    How to control the process, What is simple forumla in ajax?
    Definitely the process is very length, It should output immediately once get value from function. And seem like live program or buffering.
     
    m_maheshwariin, Jun 20, 2009 IP
  4. Tribalmaniac

    Tribalmaniac Peon

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you are extracting the values from a database, why are you even using an array? Why don't you just get the mysql result and loop through it, doing the calculation for each result?
     
    Tribalmaniac, Jun 20, 2009 IP
  5. m_maheshwariin

    m_maheshwariin Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Problem is not with array, I can process is without storing it in array.

    Problem is with function i am using. Function have a large calculation then some output. This calculation i have to use for several inputs, more than 5000 times. Thats why i am using for loop.

    But program get busy after 3-4 variable output.
     
    m_maheshwariin, Jun 20, 2009 IP
  6. livedating

    livedating Active Member

    Messages:
    161
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    83
    #6
    You can use php function get_memory_usage() to control memory from inside the script.
    Also you can change memory_limit and max_input_time in php.ini
    Alternative to max_input_time in php.ini is a set_time_limit() function.

    I would recommend to check you have a memory leak in your calculation function. One of the most popular leaks is using callback function dynamically created in the loop - it is not freed when it's created with create_function.

    Купить магазин в Киеве Продать магазин в Киеве Арендовать магазин в Киеве Сдать магазин в Киеве
     
    livedating, Jun 23, 2009 IP
  7. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #7
    It is not clear what's happening: is your script terminated, going into inifinite loop, etc.
    Insert
    error_reporting(E_ALL);
    PHP:
    at the beginning and see the errors/warnings it produces. If there is a fatal error "Maximum execution time of XX second exceeded", use the set_time_limit function to increase allowed execution time.
     
    wmtips, Jun 23, 2009 IP