Asked  7 Months ago    Answers:  5   Viewed   34 times

PHP must track the amount of CPU time a particular script has used in order to enforce the max_execution_time limit.

Is there a way to get access to this inside of the script? I'd like to include some logging with my tests about how much CPU was burnt in the actual PHP (the time is not incremented when the script is sitting and waiting for the database).

I am using a Linux box.

 Answers

76

On unixoid systems (and in php 7+ on Windows as well), you can use getrusage, like:

// Script start
$rustart = getrusage();

// Code ...

// Script end
function rutime($ru, $rus, $index) {
    return ($ru["ru_$index.tv_sec"]*1000 + intval($ru["ru_$index.tv_usec"]/1000))
     -  ($rus["ru_$index.tv_sec"]*1000 + intval($rus["ru_$index.tv_usec"]/1000));
}

$ru = getrusage();
echo "This process used " . rutime($ru, $rustart, "utime") .
    " ms for its computationsn";
echo "It spent " . rutime($ru, $rustart, "stime") .
    " ms in system callsn";

Note that you don't need to calculate a difference if you are spawning a php instance for every test.

Wednesday, March 31, 2021
 
erotsppa
answered 7 Months ago
63

$arr2 = $arr creates a deep copy. But the actual copying only happens when $arr2 is modified -- PHP utilizes copy-on-write.

If you want a "pointer" instead of a copy, use $arr2 =& $arr, which makes $arr2 a reference to $arr.

Saturday, May 29, 2021
 
BrunoRamalho
answered 5 Months ago
13

If your columns are already defined, what about remove the column iterator?

Try something like this:

foreach ($activeSheet->getRowIterator() as $rkey => $row) {
    $rowIndex = $row->getRowIndex ();
    $parsedData[$rowIndex]['order'] = $activeSheet->getCell('A' . $rowIndex);
    $parsedData[$rowIndex]['ts']    = $activeSheet->getCell('B' . $rowIndex);
    $parsedData[$rowIndex]['summ']  = $activeSheet->getCell('C' . $rowIndex);
    .
    .
    .
}
Saturday, May 29, 2021
 
Raef
answered 5 Months ago
91

I have the same error, please go to

xamppphpMyAdminlibrariesconfig.default.php

Look for : $cfg['ExecTimeLimit'] = 600;

You can change '600' to any higher value, like '6000'.

Maximum execution time in seconds is (0 for no limit).

This will fix your error.

Wednesday, June 2, 2021
 
Asnexplore
answered 5 Months ago
49

You need to change some setting in your php.ini:

upload_max_filesize = 2M 
;or whatever size you want

max_execution_time = 60
; also, higher if you must - sets the maximum time in seconds

Were your PHP.ini is located depends on your environment, more information: http://php.net/manual/en/ini.list.php

Friday, June 4, 2021
 
muaddhib
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :