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 8824705
In Process

The Archive Base Latest Questions

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

If I use Ctrl + C to exit a PHP script running in CLI,

  • 0

If I use Ctrl+C to exit a PHP script running in CLI, neither the shutdown functions, nor the destructors of instantiated objects, nor any output buffers are handled. Instead the program just dies. Now, this is probably a good thing, since that’s what Ctrl+C is supposed to do. But is there any way to change that? Is it possible to force Ctrl+C to go through the shutdown functions?

More specifically, this is about serialising and saving data on exiting of the script, so it can be reloaded and resumed the next time the script runs. Periodically saving the data could work, but would still lose everything from the last save onward. What other options are there?

  • 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-14T06:42:01+00:00Added an answer on June 14, 2026 at 6:42 am

    Obviously PCNTL is *nix only, but … You can register handlers for all the individual signals for a more robust solution, but specifically to do something when a CTL+C interrupt is encountered:

    <?php
    declare(ticks = 1);
    
    pcntl_signal(SIGINT, function() {
        echo "Caught SIGINT\n";
        die;
    });
    
    while (true) {
        // waiting for your CTRL+C
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which I use to catch any segmentation fault or ctrl-c.
I use CTRL + L all the time to delete rows in visual studio,
I often use Ctrl + P to open files, but then I'd like to
I know you can use CTRL , ALT , SHIFT , etc. modifiers for
so far i only know to use Ctrl-Shift-A to do SVN in TextMate. is
I cannot use the Ctrl + F and Ctrl + H in my SQL
I'm attempting to use the Ctrl + R , Ctrl + R command within
I use the Eclipse keyboard shortcut Ctrl + Shift + O all the time
I use the following function to show controls on my form: class procedure TFormMain.FadeControls(ctrl:Array
I find it useful and productive to use the built in Ctrl + Shift

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.