473,320 Members | 1,979 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,320 software developers and data experts.

Does PHP "cache" scripts?

A really simple script is driving me up the wall.

I have a very simply facility on a website to allow the user to reorder
items in a database table as she wishes by clicking a link that (in
this case) says "MOVE UP" and links to the script below.

This script snippet that does all the work is shown - the database
connection is established and after doing its work the script returns
the user to the referring page.

---------------------------------------------
$sql="select DisplayOrder from CreditType where Id=" . $credcat;
$result=mysql_query($sql);
$row=mysql_fetch_row($result);

$sql="update CreditType set DisplayOrder=" . (($row[0])-1) . " where
Id=" . $credcat;

mysql_query($sql);

$sql="update CreditType set DisplayOrder=" . ($row[0]) ." where
DisplayOrder=" . (($row[0])-1) . " and Id<>" . $credcat;

mysql_query($sql);
--------------------------------------------

On my own server this works perfectly - but when I upload it to my
client's shared server it sometimes works and sometimes doesn't. It is
intermittent.

Could PHP be returning a cached result of the script? If no, what on
earth can be happening? If yes, can I stop this from happning from the
script (I can't change any settings on the shared host).

Many thanks.
Steve

Sep 14 '06 #1
17 4194
On 14 Sep 2006 13:41:23 -0700, St***********@gmail.com wrote:
>On my own server this works perfectly - but when I upload it to my
client's shared server it sometimes works and sometimes doesn't. It is
intermittent.
How do you mean it doesn't work, exactly?
>Could PHP be returning a cached result of the script? If no, what on
earth can be happening?
PHP doesn't cache scripts. There's extensions like APC that cache the compiled
form of the script, but that doesn't (or shouldn't) have anything to with the
results.

MySQL can be configured to have a cache, but I don't know much about that.

Your browser can cache, but you can send headers that advise the browser not
to cache (look up the Pragma HTTP header).

Your ISP may have "transparent" caching proxies; ntl: are infamous for that.

It could be something much simpler; I don't see any error checking on the
mysql_query calls.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 14 '06 #2
Hi - thanks for the reply. The script is stripped bare - there is error
checking on the actual script and all queries work fine.

When I say it doesn't work - I just mean the user clicks on the link
and is returned almost immediately to the page as if nothing has
happened.

I have just tried it in Internet Explorer and it seems to work there -
but sometimes I have to "refresh" the page to see the effect, sometimes
it updates ok.

In firefox, sometimes it works and sometimes it doesn't. When it does,
the page updates itself to reflect the "move up" - if it doesn't work
refreshing has no effect.

If I try the link in firefox and it doesn't work and then close firefox
down and visit the same link on the same page and then try, it works
(hence a suspicion of caching or session issues).

As I say - it works perfectly in all browsers on my dedicated server.
Exactly the same script - just a different server - so I am assuming it
is a server issue.

I'm flummoxed!

Best,
Steve
Andy Hassall wrote:
On 14 Sep 2006 13:41:23 -0700, St***********@gmail.com wrote:
On my own server this works perfectly - but when I upload it to my
client's shared server it sometimes works and sometimes doesn't. It is
intermittent.

How do you mean it doesn't work, exactly?
Could PHP be returning a cached result of the script? If no, what on
earth can be happening?

PHP doesn't cache scripts. There's extensions like APC that cache the compiled
form of the script, but that doesn't (or shouldn't) have anything to with the
results.

MySQL can be configured to have a cache, but I don't know much about that.

Your browser can cache, but you can send headers that advise the browser not
to cache (look up the Pragma HTTP header).

Your ISP may have "transparent" caching proxies; ntl: are infamous for that.

It could be something much simpler; I don't see any error checking on the
mysql_query calls.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 14 '06 #3
St***********@gmail.com wrote:
A really simple script is driving me up the wall.

I have a very simply facility on a website to allow the user to reorder
items in a database table as she wishes by clicking a link that (in
this case) says "MOVE UP" and links to the script below.

This script snippet that does all the work is shown - the database
connection is established and after doing its work the script returns
the user to the referring page.
<snip>
On my own server this works perfectly - but when I upload it to my
client's shared server it sometimes works and sometimes doesn't. It is
intermittent.
hmmm, "client's shared server". I can read so much into that.

Go get a copy of iehttpheaders for MSIE or tamper data for firefox and find
out for yourself.
Could PHP be returning a cached result of the script?
No. Not unless you wrote it that way.
If no, what on
earth can be happening? If yes, can I stop this from happning from the
script (I can't change any settings on the shared host).
The webserver could be returning bad caching information. You may be
accessing it through an overzealous cache - you're code didn't contain any
cache instructions.

C.
Sep 14 '06 #4
i would compare the config on both servers, (maybe registered globals is
on on the client).

St***********@gmail.com wrote:
A really simple script is driving me up the wall.

I have a very simply facility on a website to allow the user to reorder
items in a database table as she wishes by clicking a link that (in
this case) says "MOVE UP" and links to the script below.

This script snippet that does all the work is shown - the database
connection is established and after doing its work the script returns
the user to the referring page.

---------------------------------------------
$sql="select DisplayOrder from CreditType where Id=" . $credcat;
$result=mysql_query($sql);
$row=mysql_fetch_row($result);

$sql="update CreditType set DisplayOrder=" . (($row[0])-1) . " where
Id=" . $credcat;

mysql_query($sql);

$sql="update CreditType set DisplayOrder=" . ($row[0]) ." where
DisplayOrder=" . (($row[0])-1) . " and Id<>" . $credcat;

mysql_query($sql);
--------------------------------------------

On my own server this works perfectly - but when I upload it to my
client's shared server it sometimes works and sometimes doesn't. It is
intermittent.

Could PHP be returning a cached result of the script? If no, what on
earth can be happening? If yes, can I stop this from happning from the
script (I can't change any settings on the shared host).

Many thanks.
Steve
Sep 14 '06 #5
NC
St***********@gmail.com wrote:
>
This script snippet that does all the work is shown - the database
connection is established and after doing its work the script returns
the user to the referring page.
....
On my own server this works perfectly - but when I upload it to my
client's shared server it sometimes works and sometimes doesn't.
It is intermittent.
Check register_globals setting on the two servers. Maybe something
writes over your GET/POST variables or vice versa...

Also, how do you handle MySQL errors? The behavior you are observing
is consistent with queries not being executed (which could happen when
your MySQL server is overloaded). The script tries to connect to the
MySQL server, gets an error, fails to execute the queries due to no
connection and redirects...
Could PHP be returning a cached result of the script?
No, but it is possible that the hosting company does. It is unlikely
though, because the problem is intermittent...

Cheers,
NC

Sep 14 '06 #6
St***********@gmail.com wrote:
Hi - thanks for the reply. The script is stripped bare - there is error
checking on the actual script and all queries work fine.

When I say it doesn't work - I just mean the user clicks on the link
and is returned almost immediately to the page as if nothing has
happened.

I have just tried it in Internet Explorer and it seems to work there -
but sometimes I have to "refresh" the page to see the effect, sometimes
it updates ok.

In firefox, sometimes it works and sometimes it doesn't. When it does,
the page updates itself to reflect the "move up" - if it doesn't work
refreshing has no effect.

If I try the link in firefox and it doesn't work and then close firefox
down and visit the same link on the same page and then try, it works
(hence a suspicion of caching or session issues).

As I say - it works perfectly in all browsers on my dedicated server.
Exactly the same script - just a different server - so I am assuming it
is a server issue.

I'm flummoxed!

Best,
Steve
Andy Hassall wrote:
>>On 14 Sep 2006 13:41:23 -0700, St***********@gmail.com wrote:

>>>On my own server this works perfectly - but when I upload it to my
client's shared server it sometimes works and sometimes doesn't. It is
intermittent.

How do you mean it doesn't work, exactly?

>>>Could PHP be returning a cached result of the script? If no, what on
earth can be happening?

PHP doesn't cache scripts. There's extensions like APC that cache the compiled
form of the script, but that doesn't (or shouldn't) have anything to with the
results.

MySQL can be configured to have a cache, but I don't know much about that.

Your browser can cache, but you can send headers that advise the browser not
to cache (look up the Pragma HTTP header).

Your ISP may have "transparent" caching proxies; ntl: are infamous for that.

It could be something much simpler; I don't see any error checking on the
mysql_query calls.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Andy,

Not necessarily a server issue. It could be anything between the server
and your system that's caching the page.

But it definitely sounds like a caching issue. Nothing in PHP or MySQL
would do this.

You might try adding a random string as a parameter, such as:
http://www.example.com/showinfo.php?n=12345

where you get the value from microtime() or similar. This should take
care of caching issues.

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

NC wrote:
Also, how do you handle MySQL errors? The behavior you are observing
is consistent with queries not being executed (which could happen when
your MySQL server is overloaded). The script tries to connect to the
MySQL server, gets an error, fails to execute the queries due to no
connection and redirects..
Thanks - there are definitely no sql errors (there is error checking on
the mysql queries - I removed it here for brevity.

Sep 15 '06 #8

Kim Hunter wrote:
i would compare the config on both servers, (maybe registered globals is
on on the client).
All the variables used in the script are sourced from the relevant
$_POST or $_GET. The script was designed for register_globals to be
off.

I'll check though it there are any discrepancies in the config that
might cause this problem.

Sep 15 '06 #9
Thanks everyone. I'll try your suggestions tonight and post back.

Steve

Sep 15 '06 #10
St***********@gmail.com wrote:
Kim Hunter wrote:
>i would compare the config on both servers, (maybe registered
globals is on on the client).

All the variables used in the script are sourced from the relevant
$_POST or $_GET. The script was designed for register_globals to be
off.

I'll check though it there are any discrepancies in the config that
might cause this problem.
I'm not sure but try to flush tables after all updates.

$sql="select DisplayOrder from CreditType where Id=" . $credcat;
$result=mysql_query($sql);
$row=mysql_fetch_row($result);

$sql="update CreditType set DisplayOrder=" . (($row[0])-1) . " where
Id=" . $credcat;
mysql_query($sql);

$sql="update CreditType set DisplayOrder=" . ($row[0]) ." where
DisplayOrder=" . (($row[0])-1) . " and Id<>" . $credcat;
mysql_query($sql);

# this can resolve your problem
$sql="flush tables";
mysql_query($sql);
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Sep 15 '06 #11
I have added the random number to the URL and the script now works
perfectly. In Internet Explorer. The database is updated and on return
to the list page the correct order is reflected.

In Firefox it still won't work. The database doesn't get updated and
the random number in the url doesn't change or get updated.

As my client uses IE I guess it's not that big a deal - but it is
frustrating as Firefox is my preferred browser.

Any further thoughts?

Sep 16 '06 #12
I've just run the script in Firefox again and noticed something odd.
There are two links, thus:

MOVE UP - MOVE DOWN

When I click on MOVE UP the database isn't updated but I get this in
the address box when the script returns me to the main page:

http://www.etc.com/credits.php?r=1158400161

When I click MOVE DOWN the database isn't updated and I get this:

http://www.etc.com/credits.php?r=1158400662

if I click MOVE UP again I get

http://www.etc.com/credits.php?r=1158400161

which is the same as the first time I clicked it. The r= variable is
the unix time stamp so either firefox is caching the page or my server
is somehow going back in time! ;o)

If I leave it for a while and try again, the number is updated to a new
number (and sometimes the database is updated and the order on the
credits page is changed).

Steve

StevePBurg...@gmail.com wrote:
I have added the random number to the URL and the script now works
perfectly. In Internet Explorer. The database is updated and on return
to the list page the correct order is reflected.

In Firefox it still won't work. The database doesn't get updated and
the random number in the url doesn't change or get updated.

As my client uses IE I guess it's not that big a deal - but it is
frustrating as Firefox is my preferred browser.

Any further thoughts?
Sep 16 '06 #13
St***********@gmail.com wrote:
I've just run the script in Firefox again and noticed something odd.
There are two links, thus:

MOVE UP - MOVE DOWN

When I click on MOVE UP the database isn't updated but I get this in
the address box when the script returns me to the main page:

http://www.etc.com/credits.php?r=1158400161

When I click MOVE DOWN the database isn't updated and I get this:

http://www.etc.com/credits.php?r=1158400662

if I click MOVE UP again I get

http://www.etc.com/credits.php?r=1158400161

which is the same as the first time I clicked it. The r= variable is
the unix time stamp so either firefox is caching the page or my server
is somehow going back in time! ;o)

If I leave it for a while and try again, the number is updated to a new
number (and sometimes the database is updated and the order on the
credits page is changed).

Steve

StevePBurg...@gmail.com wrote:
>>I have added the random number to the URL and the script now works
perfectly. In Internet Explorer. The database is updated and on return
to the list page the correct order is reflected.

In Firefox it still won't work. The database doesn't get updated and
the random number in the url doesn't change or get updated.

As my client uses IE I guess it's not that big a deal - but it is
frustrating as Firefox is my preferred browser.

Any further thoughts?

Still a caching problem. But not related to PHP. You might get better
answers in a group such as alt.html.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 16 '06 #14

Jerry Stuckle wrote:
Still a caching problem. But not related to PHP. You might get better
answers in a group such as alt.html.

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

Thanks. I'll try that.

Sep 16 '06 #15
St***********@gmail.com wrote:
I've just run the script in Firefox again and noticed something odd.
There are two links, thus:

MOVE UP - MOVE DOWN

When I click on MOVE UP the database isn't updated but I get this in
the address box when the script returns me to the main page:

http://www.etc.com/credits.php?r=1158400161

When I click MOVE DOWN the database isn't updated and I get this:

http://www.etc.com/credits.php?r=1158400662

if I click MOVE UP again I get

http://www.etc.com/credits.php?r=1158400161

which is the same as the first time I clicked it. The r= variable is
the unix time stamp so either firefox is caching the page or my server
is somehow going back in time! ;o)

If I leave it for a while and try again, the number is updated to a new
number (and sometimes the database is updated and the order on the
credits page is changed).
<snip>

My guess:
1. You're paying more to your hosting provider and they have some
master-slave architecture for kinda data recovery.
2. Caching issue:
a. Your ISP is caching the pages
b. As your scripting is instructing to cache (so you better post the
link & phpinfo so that someone can dig the HTTP headers and provide
suggestion) or using .html extension (some buggy proxy implementation
will flag it as static page).

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Sep 17 '06 #16
Hi all.

Just to "close" this, I wanted to let you know what I did that solved
it.

I typed:

about:config

into the Firefox address box and then changed the configuration
setting:

browser.cache.check_doc_frequency

to 1 (always check for new content).

The default is 3 (regularly check).

This has solved the problem.

This doesn't explain why the behaviour is different on different
servers - but it has solved the problem.

Thanks for all your input.

Steve

Sep 18 '06 #17
NC
St***********@gmail.com wrote:
>
I wanted to let you know what I did that solved it.

I typed:

about:config

into the Firefox address box and then changed the configuration
setting:

browser.cache.check_doc_frequency

to 1 (always check for new content).

The default is 3 (regularly check).

This has solved the problem.

This doesn't explain why the behaviour is different on different
servers - but it has solved the problem.
It does; your ISP probably has a slightly paranoid caching server on
their network...

Cheers,
NC

Sep 19 '06 #18

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

Similar topics

4
by: John | last post by:
I have read somewhere else in this newsgroup that the way to avoid the message (Warning: Page has Expired blah, blah blah ... ) when one presses the back button is to place the statement...
0
by: Gary N | last post by:
Sr. Database Administrator Permanent Position/Pittsburgh Pa $70-95K with full benefits Description A client of A.C.Coy's is looking for a Senior Database Administrator to join their team on a...
2
by: Todd Anderson | last post by:
I'm ussing this <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> to keep me html page from caching. But it's not working. Is there a javascript that will do this? Thanks in advance for your help.
3
by: Tim Marsden | last post by:
Hi, When I open my VS2003 solution it looks up "Initializing offline cache", if I end it and reopen its OK. Any suggestions? Tim
0
by: Juan Irigoyen | last post by:
How I can traduce this sentence in VB. Thanks. Dim arrSesions As DataRow() arrSesions = Context.Cache("SessionKeys").Select("xxx")
2
by: Jason Huang | last post by:
Hi, Kind of spending too much time on the no-cache issue and found out something like <% Response.CacheControl = "no-cache" %>. In my ASP.Net, a C# .aspx file, where do I put the <%...
4
by: Guadala Harry | last post by:
Is there any way for one Session to remove and update objects in another Session? I seriously doubt it, but thought I'd ask. Here's why: I have some data that is unique per user (or per session -...
0
by: miha.valencic | last post by:
Is there a way (int ASP.NET 1.1 or 2.0) to check which "Cache-Control" headers have been output or set before the page is written to output stream? There is Response.Headers property in .NET...
2
by: TheSteph | last post by:
Hi I have a SQLCommand that do updates on a table. I have a loop where I set the parameters then I call ExecuteNonQuery. For . { . Set the SQLCommand's Params Values;
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.