0

I've done a php page index.php which uses some python scripts to retrieve some informations and copy them from a file A to a file B. My problem is that if I have more than one user that access index.php, B is modified from both the users. How can I make the second user wait until the first user has finished to modify B?

Rohit.007
  • 3,414
  • 2
  • 21
  • 33
Jojo
  • 23
  • 2

2 Answers2

0

Suppose we have that function called "CopyIt".

Then let's imagine that a user is requesting index.php to be executed. The simplest way to handle this request is like this scenario :

-First, index.php wants to call CopyIt,BUT! it doesn't call it directly to copy from A to B! index.php will put this request (copy things) into Cronjob and Operation System will execute it at a reserved time.

Now, for running this scenario, My suggestion is to:

  1. Make a php file called : CopyAtoB.php [You will execute this file via php, later]

  2. Write the whole function (codes) in CopyAtoB.php

  3. Give a reserved time to every requests that index.php gets.

  4. Schedule your reserved tasks with Cronjob file. (for more information about How to use a cronjob: https://opensource.com/article/17/11/how-use-cron-linux)

GoodLuck

  • this answer is interesting, I want to give it a try. I'll let you know if it works (and then I'll accept the answer). Thanks – Jojo Jun 20 '19 at 10:11
  • feel free. btw, cronjob is for linux users. If you use WindowsOS you can work with Windows Task Scheduler https://www.digitalcitizen.life/how-create-task-basic-task-wizard – ilia Abedian Jun 20 '19 at 11:41
0

You can make one file in parallel xyz.txt.in_use and check for it every time from other location that the file is exists OR not then wait till it got deleted then after the writing completion, delete the xyz.txt.in_use, so that other can take charge on xyz.txt

Rohit.007
  • 3,414
  • 2
  • 21
  • 33
  • I decided to accept this answer because it is simpler to implement, but also Eil1 AB's answer is very good. – Jojo Jun 20 '19 at 11:17