当脚本运行超过30分钟时,PHP脚本在DB中更新记录

I have a PHP script which runs each night to update records in my DB. In my DB I also have a record for this script:

Filename

script1.php

completed

N

Once the script completes I make one last update to the DB and this is to update 'script1.php' and change it to 'Y'

If I remove everything in the file besides the last call to the DB then the script changes the 'N' to a 'Y' just fine.

The problem is that before marking as complete I am getting records and inserting them into my DB which takes 38 minutes in total.

This is probably my issue , after 38 mins the script finishes however it doesnt update the 'N' to a 'Y'.

code

upload_max_filesize = 256M
post_max_size = 256M
max_input_vars = 10000
memory_limit = 512M
max_execution_time = 3000

These are the config settings on the server , I cannot change these as these are already the max settings im allowed.

Although I get a 504 gateway timeout the records continue to insert into the DB. All the records are inserted perfectly however this 'N' isnt changes to a 'Y'.

How do I get the script to run long enough to update this 'N' to a 'Y' ?

CODE as requested

<?php
// Run Script
require_once('removed');

ignore_user_abort(true); // just to be safe

echo('Script Started.');

flush();
// Do processing here

error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('removed');
require('removed');
require('remvoed');

$filename = basename(__FILE__);
checkcrondependencies($filename);


//REMOVED DATA SUPPLIER CLASS

  date_default_timezone_set("Europe/London");


    $domainpath = realpath(dirname(__FILE__));
    $inipath = REMOVED;
    $privatepath = REMOVED;

    $connection_settings = REMOVED;
    $dbhost = $connection_settings['dbhost'];
    $dbname = $connection_settings['dbname'];
    $dbuser = $connection_settings['dbuser'];
    $dbpass = $connection_settings['dbpass'];

    //Make connection to supplier 


   $iscronfile = 'Y';

  $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  if (!$conn) {
      new_log_entry($filename,'DB Connection Failed','Y',$iscronfile);
      die("Connection failed: " . mysqli_connect_error());
  }

    // pull data from supplier 
    //push data to DB
    // Total time 38 minutes

     echo "completed";
     setcroncompleted($filename); // <<< THIS IS SUPPOSED TO CHANGE 'N' TO A 'Y'
     new_log_entry($filename,'Run Time End:'.date("Y-m-d h:i:sa"),'N',$iscronfile);

Script runs via cron? Make some limiter to limit script execution. You can make cron to fire a hour each minute but log somewhere that $script_is_busy == true and update_is_done = false. After limiter hits limit make sure $script_is_busy = false and log how far updates was made. After one minute the next cron iteration will continue updates. When update is done log $update_is_done = true;. It not big deal if cron fires "empty scipt" like if unpdate_is_dome == true ? die().