473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Re-opening a file

Hi. In my application I do something very simple - I open a file, lock
it exclusively, write some data to it and close it.

If I re-open it in the same process (I mean before the script has
ended) to read the file, I find that the data I have written doesn't
exist in there. I can't read it back until I run the script again.

My question follows: WHAT

Jul 15 '07 #1
14 1740
W Marsh wrote:
Hi. In my application I do something very simple - I open a file, lock
it exclusively, write some data to it and close it.

If I re-open it in the same process (I mean before the script has
ended) to read the file, I find that the data I have written doesn't
exist in there. I can't read it back until I run the script again.

My question follows: WHAT
Sorry, my crystal ball is in the shop. I have no idea what might be
happening. Maybe if you post your code...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 15 '07 #2
On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attglobal.netwrote:
W Marsh wrote:
Hi. In my application I do something very simple - I open a file, lock
it exclusively, write some data to it and close it.
If I re-open it in the same process (I mean before the script has
ended) to read the file, I find that the data I have written doesn't
exist in there. I can't read it back until I run the script again.
My question follows: WHAT

Sorry, my crystal ball is in the shop. I have no idea what might be
happening. Maybe if you post your code...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
No. For one thing it's private, commercial code, and secondly, I've
given enough information about the problem.

I don't appreciate people making sarcastic comments like that. If you
have no idea about the problem then keep quiet, or if you genuinely
are missing important details, make a polite request, e.g. "Are you
doing X between closing and re-opening the file?". I'm not an outlet
for problems with your insecurities and ego.

If you really are that unimaginative, then here's some code (using my
own original description as a design spec, proving my point somewhat):

define(FILE_NAME, "somefile.txt");

$dataOrig = array("here", "is", "some", "data", "to", "be",
"serialized");

$file = fopen(FILE_NAME, "w");
flock($file, LOCK_EX);
fwrite($file, serialize($dataOrig));
fclose($file);

$file = fopen(FILE_NAME, "r");
$dataNew = unserialize(fread($file, filesize(FILE_NAME)));

print_r($dataNew); // Expected output: Array ( [0] =here [1] =is
[2] =some [3] =data [4] =to [5] =be [6] =serialized )

It is not representative of the original code in terms of design or
error checking, but it does reproduce the problem on the production
server (no output, due to getting no data in the original file). It
does however run correctly on a my own web server, which suggests the
problem is one of configuration that somebody with experience in this
field could shed some light on, which I would be grateful for.

Do you see?

Jul 15 '07 #3
rf
"W Marsh" <wa*********@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Sorry, my crystal ball is in the shop. I have no idea what might be
happening. Maybe if you post your code...
I don't appreciate people making sarcastic comments like that. If you
have no idea about the problem then keep quiet, or if you genuinely
are missing important details, make a polite request, e.g. "Are you
doing X between closing and re-opening the file?". I'm not an outlet
for problems with your insecurities and ego.
You are, however, the one with the broken code that is asking the question.

--
Richard.
Jul 15 '07 #4
On 15 Jul, 15:08, "rf" <r...@invalid.comwrote:
"W Marsh" <wayne.ma...@gmail.comwrote in message

news:11**********************@57g2000hsv.googlegro ups.com...
On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attglobal.netwrote:
Sorry, my crystal ball is in the shop. I have no idea what might be
happening. Maybe if you post your code...
I don't appreciate people making sarcastic comments like that. If you
have no idea about the problem then keep quiet, or if you genuinely
are missing important details, make a polite request, e.g. "Are you
doing X between closing and re-opening the file?". I'm not an outlet
for problems with your insecurities and ego.

You are, however, the one with the broken code that is asking the question.

--
Richard.
Ah, so you've seen where the code I've posted is broken. Excellent! I
am anxious to see you elaborate further on this.

Jul 15 '07 #5
W Marsh kirjoitti:
On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attglobal.netwrote:
>W Marsh wrote:
>>Hi. In my application I do something very simple - I open a file, lock
it exclusively, write some data to it and close it.
If I re-open it in the same process (I mean before the script has
ended) to read the file, I find that the data I have written doesn't
exist in there. I can't read it back until I run the script again.
My question follows: WHAT
Sorry, my crystal ball is in the shop. I have no idea what might be
happening. Maybe if you post your code...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

No. For one thing it's private, commercial code, and secondly, I've
given enough information about the problem.

I don't appreciate people making sarcastic comments like that. If you
have no idea about the problem then keep quiet, or if you genuinely
are missing important details, make a polite request, e.g. "Are you
doing X between closing and re-opening the file?". I'm not an outlet
for problems with your insecurities and ego.

If you really are that unimaginative, then here's some code (using my
own original description as a design spec, proving my point somewhat):

define(FILE_NAME, "somefile.txt");

$dataOrig = array("here", "is", "some", "data", "to", "be",
"serialized");

$file = fopen(FILE_NAME, "w");
flock($file, LOCK_EX);
fwrite($file, serialize($dataOrig));
fclose($file);

$file = fopen(FILE_NAME, "r");
$dataNew = unserialize(fread($file, filesize(FILE_NAME)));

print_r($dataNew); // Expected output: Array ( [0] =here [1] =is
[2] =some [3] =data [4] =to [5] =be [6] =serialized )

It is not representative of the original code in terms of design or
error checking, but it does reproduce the problem on the production
server (no output, due to getting no data in the original file). It
does however run correctly on a my own web server, which suggests the
problem is one of configuration that somebody with experience in this
field could shed some light on, which I would be grateful for.
I'm not sure if you already mentioned this, but if you manuallu open the
file after running the script, are the values actually written into it,
on the server where it doesn't work? I mean have you really checked that
the problem is not in writing to it, but actually reading from it?

What does
var_dump( filesize(FILE_NAME) );
give you?
Try putting it before the line
$dataNew = unserialize(fread($file, filesize(FILE_NAME)));

If it yields zero, which might be possible for just created file it
might be getting it from cache. If this is the case, then running
clearstatcache() ought to solve the problem.

BTW, I didn't think Jerry's request for code was unreasonable. For
instance there are many ways for reading from a file. I for one couldn't
have imagined using fread($file, filesize(FILE_NAME)) for reading, cos I
always use file_get_contents. That's why I think it was good that you
provided the sample code rather than leave us scraching our heads with
nothing. When someone asks you for sample code, of course you don't need
to post the in-house production code, just something that effectively
reproduces the error.

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Jul 15 '07 #6
On 15 Jul, 16:53, Rami Elomaa <rami.elo...@gmail.comwrote:
W Marsh kirjoitti:
On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attglobal.netwrote:
W Marsh wrote:
Hi. In my application I do something very simple - I open a file, lock
it exclusively, write some data to it and close it.
If I re-open it in the same process (I mean before the script has
ended) to read the file, I find that the data I have written doesn't
exist in there. I can't read it back until I run the script again.
My question follows: WHAT
Sorry, my crystal ball is in the shop. I have no idea what might be
happening. Maybe if you post your code...
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
No. For one thing it's private, commercial code, and secondly, I've
given enough information about the problem.
I don't appreciate people making sarcastic comments like that. If you
have no idea about the problem then keep quiet, or if you genuinely
are missing important details, make a polite request, e.g. "Are you
doing X between closing and re-opening the file?". I'm not an outlet
for problems with your insecurities and ego.
If you really are that unimaginative, then here's some code (using my
own original description as a design spec, proving my point somewhat):
define(FILE_NAME, "somefile.txt");
$dataOrig = array("here", "is", "some", "data", "to", "be",
"serialized");
$file = fopen(FILE_NAME, "w");
flock($file, LOCK_EX);
fwrite($file, serialize($dataOrig));
fclose($file);
$file = fopen(FILE_NAME, "r");
$dataNew = unserialize(fread($file, filesize(FILE_NAME)));
print_r($dataNew); // Expected output: Array ( [0] =here [1] =is
[2] =some [3] =data [4] =to [5] =be [6] =serialized )
It is not representative of the original code in terms of design or
error checking, but it does reproduce the problem on the production
server (no output, due to getting no data in the original file). It
does however run correctly on a my own web server, which suggests the
problem is one of configuration that somebody with experience in this
field could shed some light on, which I would be grateful for.

I'm not sure if you already mentioned this, but if you manuallu open the
file after running the script, are the values actually written into it,
on the server where it doesn't work? I mean have you really checked that
the problem is not in writing to it, but actually reading from it?

What does
var_dump( filesize(FILE_NAME) );
give you?
Try putting it before the line
$dataNew = unserialize(fread($file, filesize(FILE_NAME)));

If it yields zero, which might be possible for just created file it
might be getting it from cache. If this is the case, then running
clearstatcache() ought to solve the problem.
Thanks. That seems like a plausible solution. I'll try it at work
tomorrow.

I don't think I can use file_get_contents in this case, because I want
to respect file locks. It would be nice if I could get
file_get_contents to do that.
>
BTW, I didn't think Jerry's request for code was unreasonable. For
instance there are many ways for reading from a file. I for one couldn't
have imagined using fread($file, filesize(FILE_NAME)) for reading, cos I
always use file_get_contents. That's why I think it was good that you
provided the sample code rather than leave us scraching our heads with
nothing. When someone asks you for sample code, of course you don't need
to post the in-house production code, just something that effectively
reproduces the error.
It wasn't the request that annoyed me, but the sarcasm. I don't want
to derail things further by arguing about it though!

Jul 15 '07 #7
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:r8******************************@comcast.com. ..
>W Marsh wrote:
>On 15 Jul, 15:27, Jerry Stuckle <jstuck...@attglobal.netwrote:
>>And BTW - in PHP there is no such thing as "private" code. Once you
give it to a customer the source is available, unless you get one of the
encryption engines, i.e. from Zend.

Well, there is. Not a single person outside of the company will ever
see this code, because it's a backend system that powers customer
facing front ends. Surely you have come across such a situation
before! Not all PHP ends up as forum software.

So? That makes it so special? ROFLMAO!
That makes it _private_. You claimed that no php code is private, because
the client will always see it. Yet, if the case happens to be that a company
has it's own IT department that produces software, it will remain private,
since no second party will have access to it. You ought to be laughing at
yourself, not to his claim.

--
Ra*********@gmail.com

"Good tea. Nice house." -- Worf
Jul 16 '07 #8
Rami Elomaa wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:r8******************************@comcast.com. ..
>W Marsh wrote:
>>On 15 Jul, 15:27, Jerry Stuckle <jstuck...@attglobal.netwrote:
And BTW - in PHP there is no such thing as "private" code. Once you
give it to a customer the source is available, unless you get one of the
encryption engines, i.e. from Zend.
Well, there is. Not a single person outside of the company will ever
see this code, because it's a backend system that powers customer
facing front ends. Surely you have come across such a situation
before! Not all PHP ends up as forum software.
So? That makes it so special? ROFLMAO!

That makes it _private_. You claimed that no php code is private, because
the client will always see it. Yet, if the case happens to be that a company
has it's own IT department that produces software, it will remain private,
since no second party will have access to it. You ought to be laughing at
yourself, not to his claim.
Nope, that doesn't make it private. It just means it has restricted
access. Different things.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 16 '07 #9
W Marsh wrote:

Oh, and BTW - I didn't even know that you were posting from Google
Groups until you mentioned it. That's when I looked at the headers and
verified it.

And it explains your postings completely.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 16 '07 #10
C.
On 15 Jul, 14:57, W Marsh <wayne.ma...@gmail.comwrote:
On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attglobal.netwrote:
W Marsh wrote:
Hi. In my application I do something very simple - I open a file, lock
it exclusively, write some data to it and close it.
If I re-open it in the same process (I mean before the script has
ended) to read the file, I find that the data I have written doesn't
exist in there. I can't read it back until I run the script again.
My question follows: WHAT
Sorry, my crystal ball is in the shop. I have no idea what might be
happening. Maybe if you post your code...
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

No. For one thing it's private, commercial code, and secondly, I've
given enough information about the problem.

I don't appreciate people making sarcastic comments like that. If you
have no idea about the problem then keep quiet, or if you genuinely
are missing important details, make a polite request, e.g. "Are you
doing X between closing and re-opening the file?". I'm not an outlet
for problems with your insecurities and ego.

If you really are that unimaginative, then here's some code (using my
own original description as a design spec, proving my point somewhat):

define(FILE_NAME, "somefile.txt");

$dataOrig = array("here", "is", "some", "data", "to", "be",
"serialized");

$file = fopen(FILE_NAME, "w");
flock($file, LOCK_EX);
fwrite($file, serialize($dataOrig));
fclose($file);

$file = fopen(FILE_NAME, "r");
$dataNew = unserialize(fread($file, filesize(FILE_NAME)));

print_r($dataNew); // Expected output: Array ( [0] =here [1] =is
[2] =some [3] =data [4] =to [5] =be [6] =serialized )

It is not representative of the original code in terms of design or
error checking, but it does reproduce the problem on the production
server (no output, due to getting no data in the original file). It
does however run correctly on a my own web server, which suggests the
problem is one of configuration that somebody with experience in this
field could shed some light on, which I would be grateful for.

Do you see?

AIR filestats are cached therefore filesize() reports the same value
after you've changed a file. RTFM for clearstatcache.

C.

Jul 16 '07 #11
On Sun, 15 Jul 2007 05:43:20 -0700, W Marsh <wa*********@gmail.com>
wrote:
>Hi. In my application I do something very simple - I open a file, lock
it exclusively, write some data to it and close it.

If I re-open it in the same process (I mean before the script has
ended) to read the file, I find that the data I have written doesn't
exist in there. I can't read it back until I run the script again.

My question follows: WHAT
It works for me okay. Would you post you're code to see what's the
problem?
--
Brendan Gillatt
www.brendangillatt.co.uk
GPG: 0x6E265E61
Jul 16 '07 #12
Jerry Stuckle kirjoitti:
Rami Elomaa wrote:
>"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:r8******************************@comcast.com ...
>>W Marsh wrote:
On 15 Jul, 15:27, Jerry Stuckle <jstuck...@attglobal.netwrote:
And BTW - in PHP there is no such thing as "private" code. Once you
give it to a customer the source is available, unless you get one
of the
encryption engines, i.e. from Zend.
Well, there is. Not a single person outside of the company will ever
see this code, because it's a backend system that powers customer
facing front ends. Surely you have come across such a situation
before! Not all PHP ends up as forum software.

So? That makes it so special? ROFLMAO!

That makes it _private_. You claimed that no php code is private,
because the client will always see it. Yet, if the case happens to be
that a company has it's own IT department that produces software, it
will remain private, since no second party will have access to it. You
ought to be laughing at yourself, not to his claim.

Nope, that doesn't make it private. It just means it has restricted
access. Different things.
Whatever you wanna call it, same difference.

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Jul 16 '07 #13
On 16 Jul, 12:10, Jerry Stuckle <jstuck...@attglobal.netwrote:
Rami Elomaa wrote:
"Jerry Stuckle" <jstuck...@attglobal.netwrote in message
news:r8******************************@comcast.com. ..
W Marsh wrote:
On 15 Jul, 15:27, Jerry Stuckle <jstuck...@attglobal.netwrote:
And BTW - in PHP there is no such thing as "private" code. Once you
give it to a customer the source is available, unless you get one of the
encryption engines, i.e. from Zend.
Well, there is. Not a single person outside of the company will ever
see this code, because it's a backend system that powers customer
facing front ends. Surely you have come across such a situation
before! Not all PHP ends up as forum software.
So? That makes it so special? ROFLMAO!
That makes it _private_. You claimed that no php code is private, because
the client will always see it. Yet, if the case happens to be that a company
has it's own IT department that produces software, it will remain private,
since no second party will have access to it. You ought to be laughing at
yourself, not to his claim.

Nope, that doesn't make it private. It just means it has restricted
access. Different things.
Wheeeeee.

That's the sound of you moving the goalposts.

Jul 17 '07 #14
W Marsh wrote:
>Nope, that doesn't make it private. It just means it has restricted
access. Different things.

Wheeeeee.

That's the sound of you moving the goalposts.
Go play with your code, troll. You obviously don't understand what
"private code" is any more than you understand how to ask questions in a
newsgroup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 18 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
1
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
10
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
by: Lothar Scholz | last post by:
Because PHP5 does not include the mysql extension any more is there a chance that we will see more Providers offering webspace with Firebird or Postgres Databases ? What is your opinion ? I must...
1
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id ...
1
by: Brian | last post by:
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
1
by: Clarice Almeida Hughes | last post by:
tenho um index onde tenho o link pro arq css, como sao visualizados pelo include todas as paginas aderem ao css linkado no index. so q eu preciso de alguns links com outras cores no css, o q devo...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.