Re: 20+ Second Delay Serving Script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Wed, 6 Dec 2023, 09:35 David Colter, <dcolter@xxxxxx> wrote:
Deepak,

There is one script in a website that takes 20-30 seconds to display its contents. It uses fopen (to record) and curl (to request an external resource). Investigating the issue lead me to discover that all program’s “processing” is completed within 1 second of the page request. There were no errors in 2 different browser consoles, nor in any error logs. 

Which script is it?

It is homemade.

Are you asking for the code?  (See below)

Can you time the parser? Before and After.


As I stated in OP, a 20-30 second delay only occurs using PHP 8.2.13 on the VPS. The delay does not occur with the same script in PHP 8.1 or PHP 8.3. And, the scripts execution completes, followed by the 20-30 second delay for the page to be displayed. I make this second claim, because I’ve echoed date() at the beginning and end of the script and a _javascript_ onload prints out a time 20+ seconds after the script’s 2 date() functions - < ½ second apart. The scripts output is not coming to the screen until after a long delay. 

Incidentally, flush() at the end of the script had no effect.

Bringing the RegistryPost class below into this main file and eliminating the fopen/fwrite functions also had no effect on stopping the long delay.

David

<?php
$target = $token = '';

/* ---------   FAA Registry   ---------- */
require_once 'classes/RegistryPost.php';
$helper = new RegistryPost();
$fullPage = $helper->getNumbers();

/* ---------   Parser   ---------- */
require_once 'admin/parser/simple_html_dom.php';

$html = str_get_html($fullPage);

if (is_object($html)) {
    $target = $helper->actionTarget($html);
    
    foreach($html->find('input') as $input) {
        if (strpos($input->name, 'Token')) {
            $token = $input->value;
            break;
        }
    }
}
?>
<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8">
    
    <title></title>
    <style>
        body { width: 300px; margin: 50px auto; text-align: center }    
    </style>
<script>
function submitForm() {
window.setTimeout(function() {
document.theForm.submit();
console.log(new Date());
}, 100)
}
</script>
</head>
<body _onload_="submitForm()">

    <p>
        Press the submit button if this page does not redirect to the FAA Registry 
    </p>
    
    <form method="post" action="" $target ?>" name="theForm">
        <input type="hidden" name="nametxt" value="<?= $_GET['name'] ?? ‘John Smith' ?>" />
        <input type="hidden" name="sort_option" value="1" />
        <input type="hidden" name="__RequestVerificationToken" value="<?= $token ?>" />
        <input type="submit" value="Submit" />
    </form>
<div>
</body>
</html>




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux