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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:33:04+00:00 2026-05-28T13:33:04+00:00

I have an mobile app that reads a JSON file that is stored on

  • 0

I have an mobile app that reads a JSON file that is stored on an Apache server. The contents of that JSON file are regenerated (using a PHP script) if something is changed via a GUI.

I am worried that trying to overwrite the JSON file in the middle of it being served by Apache might cause problems.

Does Apache obtain a read lock before serving files? If not, what will happen if I try to write it at the same time it is being served?

  • 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-28T13:33:05+00:00Added an answer on May 28, 2026 at 1:33 pm

    No. On POSIX-compatible systems, all locks are advisory anyways, so even if apache would get a read lock, the other process could just write the file.

    You can determine that with strace:

    [pid  7246] open("/var/www/file.json", O_RDONLY|O_CLOEXEC) = 11
    [pid  7246] fcntl(11, F_GETFD)          = 0x1 (flags FD_CLOEXEC)
    [pid  7246] mmap(NULL, 20, PROT_READ, MAP_SHARED, 11, 0) = 0x7f53f93da000
    [pid  7246] munmap(0x7f53f93da000, 20)  = 0
    [pid  7246] writev(10, [{"HTTP/1.1 200 OK\r\nDate: Thu, 26 J"}, ...) = 365
    [pid  7246] close(11)                   = 0
    

    Therefore, it can happen that your JSON file is only partially written. To avoid this problem, write your JSON file to a temporary file on the same filesystem, and use the atomic rename to overwrite the file.

    That way, if the open has succeeded, apache will continue serving the old file. If the rename finishes before the open, apache will get the new, completed file.

    If you worry about consistency (in the case of a power failure or so), you may also want to call fsync in the application that writes the JSON file before closing it.

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

Sidebar

Related Questions

I have a mobile app that is using LinqToDatasets to update/insert into a SQL
I am building Dojo mobile app. I have a Json file like: { Introduction:
I have a mobile app that writes to a SQL Server CE database on
I have a mobile website that allows users to upload photos using the file
I have a windows mobile app (mymobiler) that i am trying to install and
I have a mobile app webservice client that connects to a WCF webservice(on my
I have to make a mobile app that calculates the real life size of
I have been working with a Windows Mobile 6 app that is built with
I have some strange scrolling problems with my PhoneGap (using jQuery Mobile) app: I'm
I have a simple web mobile app that is calculating values in given fields.

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.