Multiple Write Access

Topics: Developer Forum
Jan 5, 2015 at 12:56 PM
Edited Jan 5, 2015 at 12:57 PM
Hello

I'm pretty new to PHPEXCEL, and already I was able to create and modify xls files.
It's a fantastic tool. However I'm wondering how things work concerning file sharing and locking file (or rows) when updating the file.

Let's assume 2 people creating one row each. How to lock the file when it is updated by the first guy ?

Does phpExcel use internally the php function : flock ?

Is there a good progrmming way to insure the file integrity ?

THanks a lot for any advice or comment.

Gégé
Coordinator
Jan 5, 2015 at 1:01 PM
On 05/01/2015 13:56, GegeMartinelli wrote:

From: GegeMartinelli

Hello

I'm pretty new to PHPEXCEL, and already I was able to create and modify xls files.
It's a fantastic tool. However I'm wondering how things work concerning file sharing and locking file (or rows) when updating the file.

Let's assume 2 people creating one row each. How to lock the file when it is updated by the first guy ?

Does phpExcel uses internally the php function : flock ?

It there a good progrmming way to insure the file integrity ?

THanks a lot for any advice or comment.

Gégé
PHPExcel doesn't provide any functionality to lock files in any way, or make any provision for concurrent access to files


-- 
Mark Baker

 _________
|.  \     \-3
|_J_/ PHP |
|| |  __  |
|| |m|  |m|

 I LOVE PHP
Jan 5, 2015 at 1:15 PM
Edited Jan 5, 2015 at 1:27 PM
Does this mean that a web server may be not shared by multiple users when using PHPExcel ?
If so what wil happen with a code like the following :
$file ="myfile.xls";
$fp = fopen($file", "r+");
flock($fp, LOCK_EX);   // lock my file
$objPHPExcel = PHPExcel_IOFactory::load($file); 
$objWorksheet = $objPHPExcel->getActiveSheet(); 
$line = $objWorksheet->getHighestRow()+1;
...
...
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
try
{
    $objWriter->save($file);
        flock($fp, LOCK_UN);
}
catch (Exception $e) 
{ 
    ob_get_clean();
    ob_start();
        die("An error was decteted");
}
```
Jan 5, 2015 at 1:35 PM
Do not bother with my question, I tried, it does not work (because the file is already open).
I'll try another way