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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:06:53+00:00 2026-05-28T06:06:53+00:00

I am new to PHP. I understand I can use flock() to lock a

  • 0

I am new to PHP. I understand I can use flock() to lock a file and avoid race conditions when two users reach the same php file adding content to the lockable file.

However, what happens if a php process crashes? What happens to the next user waiting for the lockable file? What happens if the server crashes (someone pulls the plug)? Is the lock automatically released? Will the file remain locked after rebooting the server?

To make it short, does PHP make sure such critical situations (i.e., lock not explicitly released) are handled properly? If not, how should one deal with these situations? How to recover from these?

  • 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-05-28T06:06:54+00:00Added an answer on May 28, 2026 at 6:06 am

    Locks are handled by the OS. Therefore:

    • if a process crashes, all locks it held are released (along with any other kind of resource it held)
    • if the system crashes, locks are meaningless because they do not “carry over” to the next reboot

    PHP does not need to do anything special other than use the OS-provided mechanism for locking files, so in general you are perfectly safe.

    However, if your web server setup is such that each request is not handled by a new process then if one request is abnormally terminated (let’s say a thread is aborted) the lock will persist and block all further requests for the lock, quickly resulting in a deadlocked web server. That’s one of the many reasons that you really, really should not use setups that do not provide process-level isolation among requests (disclaimer: I am not a web server expert — I could be wrong in the “should not” part, even though I doubt it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i'm new to php and mysql. I'm wondering how can i use PHP
Has anyone ever modified the post-new.php file in their WordPress installation? I want to
Im new to PHP and I can't figure out what the rules are for
I've spent whole days with PHP's DOM functions but i can't understand how it
Sorry, I'm very new to PHP, and I can't find anything about this in
We can modify the document root directory path for PHP using $_SERVER['DOCUMENT_ROOT'] = to/some/new/directory;
I'm new to PHP and don't understand what the point of <<<_END is. Could
I'm trying to use a MERGE INTO statement in my php file to update
I'm relatively new to client-side programming coming from the PHP/MySQL environment. I understand the
To put it simply i am a fairly new PHP coder and i was

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.