Welcome Guest, Not a member yet? Register   Sign In
Best practices for app initialization?
#1

[eluser]Doug Lerner[/eluser]
In general, I like to make sure things are properly initialized when my apps run. For example:

* Make sure the database tables are up-to-date with any changes to a schema.
* Make sure certain files exist, etc.

In my current development environment, I run "initialization functions" that automatically run themselves one time when the server starts up.

In a PHP-based app, the server itself is running all the time and the app only runs when one of it's URLs get called. I wouldn't want the overhead of running all the initialization scripts each time somebody calls one of the app's URLs.

What do people usually do to handle this situation?

Perhaps run an initialization script on every page, but have it immediately return if it checks some "last updated timestamp" and sees that no updates to the tables, etc. is required?

doug
#2

[eluser]Aea[/eluser]
Initialization?

The only time I ever even needed up look at such a thing was when dealing with an extremely complex system. You should have your files in the right place without needing to run a check to see if they are.

Why do you need to do this?
#3

[eluser]Doug Lerner[/eluser]
[quote author="Aea" date="1215759007"]Initialization?

The only time I ever even needed up look at such a thing was when dealing with an extremely complex system. You should have your files in the right place without needing to run a check to see if they are.

Why do you need to do this?[/quote]

(1) Well, if I'm creating a complex app for a customer and the customer has access to the filesystem with FTP, maybe the customer might accidentally delete a file somewhere. So I would want to check for its existence.

(2) Or let's say I develop an app and several customers are using it at different sites, and I want to update some tables in the database to reflect some bug fix or enhancement. Rather than go into each table and manually make the adjustment for each site running the app, wouldn't it be nice for the app to update the tables automatically if they haven't yet been updated?

There are lots of reasons, for robustness, or for the sake up automating updates, where you might want to run an initialization script and make sure everything is ok and up-to-date.

doug
#4

[eluser]Randy Casburn[/eluser]
@doug -- you're asking all the right questions - you're just coming at this from angles that folks may not be accustomed to working with...

The story you're likely to see here is -- users shouldn't be messing with any files unless they own them! So I'll show you that CI was designed to allow exactly that!

One of the beautiful design features that CI was built around was meant to address the type of question you've asked here. Now there are many others, such as security, and the other non-functional "ilities" that this particular feature was meant for...so what is this beauty? It's the file structure and how CI "finds" the files it needs to operate with.

Go here http://ellislab.com/codeigniter/user-gui...rence.html and look at the bottom left of the page for the directory structure. CI is designed so that you can move the entire system folder altogether. So you can move the entire "system directory" and all its subdirectories, including your "application directory", to a location of your choosing outside the DOCROOT of your webserver If you think about what I just said, your "system" has remained robust, and your users cannot gain access to any of the files there. If you want them to have access to files, provide that elsewhere and manage those carefully. Using this method, you've ensured that your "system" can not be damaged errantly. It also makes updating the "system" at upgrade time almost effortless.

There are many people in these forums that either don't understand the importance of that feature or just simply think the safety, security and robustness it provides is too much of a pain. There has even been a campaign to "undo" the directory structure.

I commend Rick for this single feature and hope it stays forever.

It sounds like you have a real-time programming background when it comes to garbage collection, synchronization, versioning, document management, etc. in your databases and file systems. What most of us do with our web based systems, since they are running services constantly, is take advantage of one of those services. On Windoze boxes we use the task scheduler and on Linux/Unix/Others we use Cron jobs to automate the running of CLI based PHP scripts to do these things in the background.

I hope this is helpful. I realize your answer is really in the last sentence, but I couldn't resist with all the other garbage :roll:
#5

[eluser]Doug Lerner[/eluser]
Thanks for your reply, Randy. Yes, I was mostly concerned with maintaining upgrades to the schema and doing things like triggering a new migration if and only if needed, and things like that.

doug




Theme © iAndrew 2016 - Forum software by © MyBB