Growing a Hairball

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the page itself is still running the interface into the builder script. The page itself combines whatever you want into the hashstring, performs the hash and looks in the code table for a match against that user level and hashstring. If none is found (unlikely), it calls the builder script that'll engineer the code needed, then it updates the table with this new code. Everything remains the same because each user has their differing inputs that they have sent to the interface script.
ProjectPerko
Forum Newbie
Posts: 14
Joined: Mon Oct 04, 2004 11:11 am

Post by ProjectPerko »

Wait, wait, I think I'm misunderstanding something. The page itself isn't running anything. The page is a cold output - anything it runs is run precisely once, upon loading. I thought this was the way it had to be. If I can make the page run something ON COMMAND as opposed to at the beginning, all my problems would be solved.

As far as I know, PHP can't do this. Javascript can... but I have NO IDEA how to even get started on linking Javascript to emails and databases.

On the downside, the hash string you suggest is now user-specific, meaning that the only thing this solves is the problem of code vanishing when a user does something else. However, the cost is too high: I would need to totally re-implement everything, and the table would rapidly bloat to enormity.

-Craig
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's not user specific, it's input specific.

eval() can be run anywhere any other php code can run, so yes, it is on command.
ProjectPerko
Forum Newbie
Posts: 14
Joined: Mon Oct 04, 2004 11:11 am

Post by ProjectPerko »

feyd wrote:eval() can be run anywhere any other php code can run, so yes, it is on command.
Could you please point me towards a demonstration of how to execute PHP code IN a page at some point other than right at the beginning, such as upon a button press?

-Craig
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

a button press is a seperate page request. you can do any amount of operations you want before or after the eval() runs (provided the eval'd code doesn't contain an exit type command :P)
ProjectPerko
Forum Newbie
Posts: 14
Joined: Mon Oct 04, 2004 11:11 am

Post by ProjectPerko »

Good, I thought I had missed something important. So that means that all the page's PHP runs as soon as the page is loaded. Instantly. If you want PHP to react to a button-push, you have to have the button refer to another page, or load up some kind of stored PHP, or some other method which makes more PHP run immediately upon loading the next page. Essentially, the PHP has to be external to the page with the button on it, because the page with the button on it has ALREADY RUN, and can run no more (a new instance could run, but not the same instance).

So then:
feyd wrote:the page itself is still running the interface into the builder script.
What is this? Tell me more about what this means.

-Craig
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Image

more clear now?
ProjectPerko
Forum Newbie
Posts: 14
Joined: Mon Oct 04, 2004 11:11 am

Post by ProjectPerko »

This looks like something you developed specifically for this thread. It looks very clear.

So, when someone presses a button, the submission goes to the submission processing script, which searches for the hash. If the hash exists, it runs that code. If it doesn't, it generates the new code and runs it. Fine, except how it handles multiple simultaneous users. Let me demonstrate with this thought experiment.

Anna goes to the page and loads up the HTML. She then clicks on the button. Our hash table creates new code for her. It runs fine.

The next day, she and Bob log in at the same time. Bob's a bit of a slowpoke, though. They both get the same HTML, but Anna clicks nice and fast, being more experienced. She gets the correct result. Then Bob clicks.

What happens? The hash program is obviously out of date, and was for Anne anyway. So we recalculate it. And we have, at the very least, a possible inaccuracy as code made for a page with different entries is run. Obviously, this isn't something which is acceptable, so we have to use the version of code which is accurate for the page.

Assuming that Bob's code was generated when the HTML was generated, as opposed to at the hash check, we can have his 'correct' code on file for retreival. But even then, we have to know whether we want to use this out-of-date code or generate new code. We could always use the out-of-date code, if we are careful to generate replacement code with each generation of HTML.

But, wait, we've just described exactly what I'm doing, except we're keeping all the old code, instead of discarding it.

So... what's the advantage?

-Craig
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

My approach isn't self modifying code. The scripts on the server are not intended to ever change. Only the database is expected to change. To my system of though, it doesn't matter who clicks what, the input is exactly the same. Their user levels may vary, but the input is the same. If their user level and input matches, they will recieve the exact same page.. it may be filled with differing data, but that is up to how you code the cached pages.. if they are hardcoded data, then you're wasting a lot of space, as it's too specific. Remember, generics..

Old code? Code should only be thrown away when it actually becomes outdated. Which only happens when the table is dropped, or altered (the structure, not the data). Changing data does not constitute old code normally.
ProjectPerko
Forum Newbie
Posts: 14
Joined: Mon Oct 04, 2004 11:11 am

Post by ProjectPerko »

Then how would your system deal with the example given several posts ago? There are N entries at any given time, and each of them has a button. There are exactly N buttons, no more, no less, but N varies dramatically from post to post. What am I missing in your solution?

-Craig
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ProjectPerko wrote:Then how would your system deal with the example given several posts ago? There are N entries at any given time, and each of them has a button. There are exactly N buttons, no more, no less, but N varies dramatically from post to post. What am I missing in your solution?
ProjectPerko wrote:Interesting. Lets look at an example. I have a table of N entries for things currently on loan. One major function for this would be to display all the things currently on loan (and any pertinent data), as well as a 'returned' button next to each. Once pressed, the item is marked returned/available, and it is no longer displayed on that particular page. As well, any item that is modified to be taken out (on another page) shows up here.
The number of records has no baring on how the processing script would see the input. If each record has a button it's still a generic, it sends a record. Potentially some additional information is passed via the post, session or somesuch concerning which table or linkage between tables the input pertains to.. Whatever you require to generate a unique hash record so your script can create the generic code needed to manipulate whatever it is.
ProjectPerko
Forum Newbie
Posts: 14
Joined: Mon Oct 04, 2004 11:11 am

Post by ProjectPerko »

Ah, I see. Hmmm. That is probably a better solution than mine.

Thanks! I'll have to think about it.

-Craig
Post Reply