English 中文(简体)
检查文件
原标题:testing locking a file
  • 时间:2012-05-08 07:47:16
  •  标签:
  • php

I locked a file and I am trying to test how the system reacts to a locked file. I would like other processes to wait for the process to be released until they can require_once that file again and not to come back with an error.

问题不是我做的事,我似乎无法锁定档案,在另一个进程要求档案时也做一些等待,并且看到系统对该锁档案的反应。

I tried
1. sleep() which doesn t work, it halts the whole php engine.
2. I created a batch file that simply pauses until you hit enter. and used exec("cmd.exe /c START c:\1.bat");

因此,主角是,所有程序实际上都是任务的一个系列,这样,如果出于任何原因暂停使用,那么所有其他程序都是如此?

so How can I test if a file is locked ?
But of course if I am right, what s the point in locking the file whatsoever if other processes can t access it anyway?

最佳回答
$file = fopen( somefile.php ,  r+ );

while(!flock($file, LOCK_SH | LOCK_NB)) {
    sleep(1);
}

require  somefile.php ;

由于锁 t似乎在营地内工作,你需要检查是否有锁。

问题回答

the require_once is handled by php. Because of that, you cannot simply acquire a lock for it AFAIK. If you look at file locking, refer to this
It states that you should use locks whenever you try to access the locked file.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签