Script runs twice

A

Anonymous

Guest
The below script on a server with PHP-FPM and PHP 8 runs twice. Second time exactly after 1 minute. Stack with Nginx in front and Apache in the back. Already set timeout exec and input to 1 hour.
*******************************
<?php

/*
* The purpose of this script is to see if cron jobs running more than 1 minute
* recall themselves

You can add a message by using &note=ThisUsingCronMessage

call like: https://wdleadscalls.org/cronjobs/testmulticall2.php?note=MyNoteForYou

*/

//Did they add a note
if (isset($_GET['note'])){
$note = $_GET['note'];
}else{
$note = "";
}



$Now = date('Y-m-d H:i:s');
echo "<h2> Starting This At $Now (Note:$note)</h2>";
$fp = fopen('LOGtestmultical2.txt', 'a');//opens file in append mode.
$Now = date('Y-m-d H:i:s');
$Msg = "\n Program Launched At: $Now";
fwrite($fp, $Msg);

fclose($fp);

$StartNow = $Now;

//Sleep for 4 minutes
sleep(241);


$fp = fopen('LOGtestmultical2.txt', 'a');//opens file in append mode.
$Now = date('Y-m-d H:i:s');
$Msg = "\n Program Finished At: $Now Started At:($StartNow) (Note:$note)";
fwrite($fp, $Msg);

fclose($fp);


$Now = date('Y-m-d H:i:s');
echo "<h2> FINISHING This At $Now Started At:($StartNow) (Note:$note)</h2>";

Any idea why? Where should I look?
 
"Stack with Nginx in front and Apache in the back"
what does it mean?

It looks like the issue is somewhere else
 
The behavior you describe, i.e. the script runs twice. The first time it runs immediately, the second time he runs a minute later. This can be caused by a combination of factors related to server configuration and how the script is accessed.

Possible causes may be related to PHP-FPM and Nginx server configurations. PHP-FPM can be configured with a process manager that keeps PHP-FPM workers alive for a specified period of time in order to process subsequent requests more efficiently. Combining this behavior with his default Nginx configuration can cause the script to run multiple times within a period of time.

Consider the following steps to investigate and resolve the issue:


1. Nginx configuration:
Check your Nginx configuration file and make sure you don't have duplicate or misconfigured server blocks or locations pointing to the same PHP script. Ensure FastCGI caching and other caching mechanisms are disabled or properly configured for your use case.

2. PHP-FPM configuration:
Check the PHP-FPM configuration file "php-fpm.conf" or another pool configuration file. Check the settings related to the process manager. B. "pm.max_requests" or "pm.max_children". These settings control how PHP-FPM manages worker processes. Adjusting these values may help solve the problem.

3. Access logs:
Analyze the access logs of your web servers (both Nginx and Apache) to see if there are multiple requests for the same script in a short period of time. Look for unusual patterns or requests that trigger the script multiple times.

Four. Caches and proxies:
If you use caching mechanisms (such as Varnish) or reverse proxies in front of Nginx, make sure they are properly configured and do not result in duplicated requests or incorrectly cached responses.

5. Browsing behavior:
Don't let your browser or browser extension automatically refresh or re-request your scripts.

By looking into these aspects and tweaking your server configuration, you should be able to identify and fix her script running twice issue. Additionally, monitoring server logs and observing network traffic can provide valuable insight into the requests being made and help identify the root cause.
 
Back
Top