php-general Digest 14 Nov 2011 06:27:22 -0000 Issue 7566

Topics (messages 315666 through 315670):

Re: speeding up heavy web apps with a php-js cache manager
        315666 by: Ashley Sheridan

Novice MySQL problem
        315667 by: drive view
        315668 by: Jim Giner
        315669 by: tamouse mailing lists
        315670 by: drive view

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Sun, 2011-11-13 at 18:39 +0100, rene7705 wrote:

> Hi.
> 
> I'm developing a CMS, with lots of javascript code.
> I haven't been satisfied with my page initialization speeds, so I've
> started on a caching system.
> 
> First, i used to call up javascript as needed, and just-in-time. But that,
> on a localhost setup, results in a second and a half delay.
> So now I include all javascript for the entire CMS as inline js in the
> <head> of index.php. Index.php gets gzipped of course.
> The difference is really noticeable, without looking at any counters even.
> 
> So far so good.
> 
> Now I'd like to implement a caching system for ajax requests.
> I was thinking to take URL, GET, and POST send parameters, and compare such
> a set to items in a local js cache.
> 
> If the local cache is not available, the ajax request is sent as normal,
> and the result is put in the cache.
> Javascript implementation could be as easy as changing
> jQuery.ajax(ajaxCommand) to cacheManager.ajax(ajaxCommand)
> 
> If the local cache is available, the onSuccess handler of the ajax request
> is called with the cached data.
> 
> On the server end, the cached items are put in a global JSON "FAT" file,
> again with URL, GET and POST as keys to a flat plaintext filename.
> 
> On the server, any "normal" ajaxable URL will call php code to update the
> server end cache.
> 
> Index.php would query the cache for a "subscription", a list of cache
> URL+GET+POST keys, and include these cached items as
> <div id="cache_idx" style="display:none"><!-- {"keys" :
> {URL+GET+POST+LAST_MODIFIED}, "data" : "cached-data"} --></div>
> From where the javascript cache manager would be able to find the data.
> 
> The javascript cache manager would include some kind of polling system, to
> get near realtime updates for it's cached data.
> 
> I'm convinced caching of ajax results would further increase my page
> initialization speeds.
> 
> I'm interested to learn about potential pitfalls, any opensource libraries
> that already do this, or any other tips you can think of.
> 
> Thanks for your time.


You shouldn't really cache POST requests. GET data is only ever meant to
fetch data from a server, which works well with caching, but POST is
meant to change the state of something on the server, so it may never
make sense to cache that, and could cause problems later on with things
being cached even if they appear as if they shouldn't.

If there are certain chunks of the content that will never change then
you could cache those I guess, although not sure how you would be able
to do that at the server level.

Another way to add some speed is to minify your Javascript, be it inline
or in a different file, which results in less bandwidth being used to
send the data, and less time to send it as it's smaller. Images can be
combined into a sprite map which can reduce the requests in the same way
you reduced them by making your Javascript inline.

If you use libraries like JQuery, use a public one such as that found on
Google Code. Many sites use it, so it is more likely a user has it
cached on their machine already from visiting another site that uses it.

These are all pretty basic techniques, and although they don't answer
your question exactly, they may be useful for you to achieve the same
goal.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Hi,

I'm a novice to MySQL and am currently facing the following difficulty.
I'm trying to update a table with a row of data the primary key of which is
an ID which I believe is an auto incrementing serial number.  My first
question is how to check if this is the case.

Secondly while trying to insert such a row leaving out this column mySql is
inserting the row at ID 0 (the previous ID's in the table are from 1 to 9),
but then will not take further inserts.

Thanks for any help available.


Regards

Toni

--- End Message ---
--- Begin Message ---
"drive view" <drivev...@gmail.com> wrote in message 
news:cam4sn2ip7yncw2-2soq-vjk8suer7u5x96fvpeqoitkkcaj...@mail.gmail.com...
> Hi,
>
> I'm a novice to MySQL and am currently facing the following difficulty.
> I'm trying to update a table with a row of data the primary key of which 
> is
> an ID which I believe is an auto incrementing serial number.  My first
> question is how to check if this is the case.
>

If you are updating a row, you should already know the id of the record, so 
in your update statement you reference it in the where clause.   (ie, "where 
rec_id = $curr_rec_key")

> Secondly while trying to insert such a row leaving out this column mySql 
> is
> inserting the row at ID 0 (the previous ID's in the table are from 1 to 
> 9),
> but then will not take further inserts.
>
> Thanks for any help available.
>
>
> Regards
>
> Toni
>

I don't know what the problem here is.  Personally I never use auto-inc 
fields. 



--- End Message ---
--- Begin Message ---
On Sun, Nov 13, 2011 at 3:43 PM, drive view <drivev...@gmail.com> wrote:
> I'm a novice to MySQL and am currently facing the following difficulty.
> I'm trying to update a table with a row of data the primary key of which is
> an ID which I believe is an auto incrementing serial number.  My first
> question is how to check if this is the case.

Note: this question would probably be better directed at a mysql
forum. It's not really a PHP question.

If you can run mysql at the command line on the server, you should be
able to examine the table to see it's structure:

EXPLAIN tablename;

Will show you the schema for that table and whether your ID is set
auto_increment.


> Secondly while trying to insert such a row leaving out this column mySql is
> inserting the row at ID 0 (the previous ID's in the table are from 1 to 9),
> but then will not take further inserts.

This seems to indicate to me that ID is not set auto_increment. Once
you set a value that is the primary key, MySQL will not allow more
inserts over this value.

But do take a look at the table structure just to be sure.

Here's an excerpt of explain from one of my data bases with ID as the
primary key, auto_increment set:

mysql> explain wp_posts;
+-----------------------+---------------------+------+-----+---------------------+----------------+
| Field                 | Type                | Null | Key | Default
          | Extra          |
+-----------------------+---------------------+------+-----+---------------------+----------------+
| ID                    | bigint(20) unsigned | NO   | PRI | NULL
          | auto_increment |
| post_author           | bigint(20) unsigned | NO   | MUL | 0
          |                |
| post_date             | datetime            | NO   |     |
0000-00-00 00:00:00 |                |

(I hope that doesn't come out too garbled, if possible look at it with
a monospaced font. If it did, you can see it better at
http://pastebin.com/13uG7s9g )

At any rate, you can see in the "Extra" column it says that ID is set
to auto increment.

If that is missing from your ID, then your ID is going to have to be
set manually from by the insert, and you're going to have to do
something like query the data base for the max ID number currently and
increment it for next insert. This can be problematic with possible
concurrent updates, so you'll also probably want to look at locks to
prevent someone from doing the same thing, and getting their insert in
before you have a chance to.

Take a look at
http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-transactions.html to
get some idea of what needs to happen.

On the other hand, if your ID *is* set to auto_increment, then you may
have another issue.

--- End Message ---
--- Begin Message ---
Thanks alot for your help.  I set the auto increment as suggested and it
worked.

Regards

Toni

On Sun, Nov 13, 2011 at 10:43 PM, drive view <drivev...@gmail.com> wrote:

> Hi,
>
> I'm a novice to MySQL and am currently facing the following difficulty.
> I'm trying to update a table with a row of data the primary key of which is
> an ID which I believe is an auto incrementing serial number.  My first
> question is how to check if this is the case.
>
> Secondly while trying to insert such a row leaving out this column mySql
> is inserting the row at ID 0 (the previous ID's in the table are from 1 to
> 9), but then will not take further inserts.
>
> Thanks for any help available.
>
>
> Regards
>
> Toni

--- End Message ---

Reply via email to