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

  • Home
  • SEARCH
  • 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 8329315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:44:25+00:00 2026-06-09T01:44:25+00:00

Ok, ok .. so right now I’m freaking out. index1.php <? function write_file($filepath,$filecontent) {

  • 0

Ok, ok .. so right now I’m freaking out.

index1.php

<?
function write_file($filepath,$filecontent) {
    $openedfile = fopen($filepath,"w+"); //replace with $openedfile = fopen($filepath,"a"); just in case
    flock($openedfile, LOCK_EX);
//add here fclose($openedfile); to work
//add here $openedfile = fopen($filepath,"w+"); to work
    fwrite($openedfile,$filecontent);
    flock($openedfile, LOCK_UN);
    fclose($openedfile);
}
function read_file($filepath) {
    $openedfile = fopen($filepath,"r+");
    flock($openedfile, LOCK_SH);
    sleep(10);
    $filecontent = file_get_contents($filepath);
    flock($openedfile, LOCK_UN);
    fclose($openedfile);
    return $filecontent;
}
write_file("Readme.txt","test 1");
$f1 = read_file("Readme.txt");
echo $f1;
?>

index2.php

<?
function write_file($filepath,$filecontent) {
    $openedfile = fopen($filepath,"w+"); //replace with $openedfile = fopen($filepath,"a"); to work
    flock($openedfile, LOCK_EX);
//add here fclose($openedfile); to work
//add here $openedfile = fopen($filepath,"w+"); to work
    fwrite($openedfile,$filecontent);
    flock($openedfile, LOCK_UN);
    fclose($openedfile);
}
function read_file($filepath) {
    $openedfile = fopen($filepath,"r+");
    flock($openedfile, LOCK_SH);
    $filecontent = file_get_contents($filepath);
    flock($openedfile, LOCK_UN);
    fclose($openedfile);
    return $filecontent;
}
write_file("Readme.txt","test 2");
$f1 = read_file("Readme.txt");
echo $f1;
?>

I run index1.php, then after 2 sec I run index2.php. Index2.php waits for index1.php as expected but index1.php shows nothing after 10 sec, while index2.php shows “test 2”.
What is going on?

EDIT: I figured it out :D. I changed

$openedfile = fopen($filepath,"w+");

to

$openedfile = fopen($filepath,"a");

in second php and it doesn’t wipe readme.txt upon index2.php execution anymore.

  • 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-09T01:44:27+00:00Added an answer on June 9, 2026 at 1:44 am

    Doesn’t this has to do something with the fact your readme.txt is actually empty for a very short period of time when you open the file to write in it? I thought PHP took out the entire text, and than replaced it with the entire text + addings. When index1.php wants to read the file, index2.php has just cleared it perhaps? You can check this in the apache logs by the way.

    EDIT: also, immediately after unlocking the file, index2.php takes control over it, overwriting TEST 1 with TEST 2.

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

Sidebar

Related Questions

Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the
Right now, I've just some code which fetches the picture from the URL directly.
Right now I have a function, in a class that is used to listen
right now i have this <script type='text/javascript'> $(#beau).click(function(){ $(#beau).animate({margin-Top: 738px}, fast); }); </script> and
Right now, I have a script which uses PHP's tokenizer to look for certain
this is what i have right now Drawing an RSS feed into the php,
Right now I'm stuck between using PHP's native session management, or creating my own
Right now I'm doing something like this: RewriteRule ^/?logout(/)?$ logout.php RewriteRule ^/?config(/)?$ config.php I
Right now in my basic event simulation engine, I simply just resort the list
Right now I'm trying to figure out how to create a custom UI component,

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.