Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:10:14+00:00 2026-06-18T06:10:14+00:00

I need to manage on-server synchronization between a classic database and a big amount

  • 0

I need to manage on-server synchronization between a classic database and a big amount of xls files.

If they are synchronized i perform all the operation over DB and have no problems.

Periodically some of these files are added to the server, and i need to synchronize them. They could be few, but very long, order of hundred thousands rows.

If i catch new of them i start a sync procedure. Sync procedure is proven to last short enought to not exceed Maximmum Execution Time that PHP trig after say 30secs for 1 file. But when i have more files it’s likely to exceed it.

I can not override the PHP time limit.

Right now i have a transaction that backroll if last file sync’tion failed.
And have to reload the page untill i see a sync failed/succeeded message.
This works, but it is not very nice at all.

Choices:

  1. with register_shutdown_function print rest of the page ( possible? ) and tell to reload
  2. with a custom script same thing in proximity of time limit
  3. Any way to complete the sync in background? and maybe notice it to the page through
    ajax maybe?

What would be more the suitable choice? is there any 3rd way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:10:15+00:00Added an answer on June 18, 2026 at 6:10 am

    There is nice trick to bypass the time limit, but it may lag your server if not done properly. Based on this script, I have written pure PHP CRON alternative.
    What do you do is, that you make HTTP client disconnect but you keep script running. This is most important – then, the script can call itself without getting stuck on istelf.
    To do this, it is impotant to send http header Content-Length.

    <?php
    ignore_user_abort (true);    //Tells PHP to ignore connection state
    ob_start();
    echo "Loop started\n";
    $size = ob_get_length();
    header("Content-Length: $size"); //Send exact output size to make sure client disconnects
    header("Connection: close");     //Tells client to disconnect
    ob_end_flush();
    ob_flush();
    flush();     //Clean all buffers
    if(session_id()!="")
      session_write_close(); //Close the session so that the user can use other scripts on the site
    /*Here, the script runs even if client is connected*/
    ?>
    

    Now, there is the recursive part which is very dangerous. You should make a file, telling the script that it is already running to avoid multiple threads. Like this:

    if(file_exists("secure_key"))
      exit;
    else
      file_put_contents("secure_key",time());
    

    Becaus you’ve said that you are syncing some data, you may need one more file (or MySql table) to store information about synchronisation process. This would make it possible to inform user about request progress, maybe using AJAX, like you wanted. This would make whole application look very professional 🙂
    You may know that, but if it is FOR or WHILE loop, in which you are syncing, it is also great to save start time in constant so you can quit and save without problems:

    define("STARTTIME",time());  //Right now
    define("MAXTIME",ini_get('max_execution_time')); //Max execution time
    define("SAFE_EXIT_TIME", 4);  //4 seconds to save & quit
    
    /*preparation*/
    while(time()-(STARTTIME-SAFE_EXIT_TIME)<MAXTIME) {
        /*Synchronize*/
    }
    unlink("secure_key");         //delete the antistuck file
    get_headers(/*scriopt url*/); //call itself
    exit;                         //quit
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to manage the trace files for a database on Sql Server 2005
i need to connect to another server we manage and have it's results (in
I need to manage hierarchy data storing in my database. But I have a
I need to create an application capable to modify and manage files on IOS.
I'm developing an Inno Setup installer and I need to manage an IIS server
I need a way to distinguish development server in Django (run eg. by ./manage.py
I need to checkout and manage a project from TFS (Team Foundation Server) and
I need to manage long running TCP socket connections to an external server from
I need to create and manage users in WSO2 Identity Server 3.2.3 through API,
I need to manage server sessions in iPhone. As I researched there are many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.