Piotras' blog: Archive
2007-08-01 - 2007-08-31
include VS mgd_include_snippet
Posted on 2007-08-07 14:35:16 UTC.
To make this test I used Midgard2 from trunk ( do not think to run it on production machines for a while ;) and PHP5 5.2.
I created 100 snippets named 1,2,3,4... in /AegirCore/argv0/browse/ snippetdir tree. And 100 files in /usr/share/php/AegirCore/argv0/browse.
Test was simple:
for($i = 1; $i < 100; $i++) {
$s = new midgard_snippet();
$path = "/AegirCore/argv0/browse/".$i;
$s->get_by_path($path);
}
And
for($i = 1; $i < 100; $i++) {
$path = "AegirCore/argv0/browse/".$i;
include $path;
}
I ran script 10 times, and got average times:
- mgd_include_snippet: 0,0054 sec
- include : 0,0080 sec
Interesting thing is fact that second case ( with files included from filesystem ) needed the same amount of time which snippets used, when I defined full path to included files.
Is code loaded from files faster than the one loaded from database? Myth. Only easier to maintain. Yet... :)
midgard_setup is getting better
Posted on 2007-08-10 14:08:03 UTC.
Have to mention about this before weekend :)
midgard_setup, a datagard replacement is now able to create fully functional ( I hope so :) Midgard database. Example code is simple:
$s = new midgard_setup_cli();
$s->save_config();
$sd = new midgard_setup_database($s->midgard_config);
$sd->create_database();
$sd->update_database();
A nice feature of __update_database__ method is fact that it also tries to create tables in case if one doesn't exist for specific class. It also can be used in Apache environment without security risk, as it can create tables only for classes registered via MgdSchema.
Also, I remined myself that Midgard unified configuration file can be managed with midgard-python bindings.
Next step is to install pear packages.
midgard_setup_pear
Posted on 2007-08-17 11:42:53 UTC.
It's really nice to have another part of new PHP based Midgard installer. midgard_setup_pear is quite small class ( despite the fact it's small, it's not easy to implement with completely undocumented PEAR classes ) which is responsible to install MidCOM packages from midcom pear channel.
Constructor
Very trivial:
$msp = new midgard_setup_pear();
Finally, constructor must accept midgard_config object, but at this moment it's not important.
Discover channels
$msp->set_channels();
This method update pear.php.net channel. Add pearified.com channel and discover, if it doesn't exists in your pear setup. Add pear.midcom-project.org and discover it. And, at the updates channels to fetch most recent packages info. The main goal is to update channels, so you can invoke it anywhere and as often as you need.
Install Role packages
$msp->install_midcom_roles();
Installs pearified/Role_Web, midcom/Role_Mgdschema, midcom/Role_Midgardsql' and 'midcom/Role_Midgardelement role packages.
Separate method is needed because every role package has additional config keys which have to be set. And of course this method does it for you.
If one of the package is already installed, midgard_setup_pear will inform you about this fact, and will go further a nice ellegant way:
MIDGARD SETUP: Role_Midgardelement already installed
Install packages
$msp->install_base_packages();
Installs all base and mandatory packages required to start using midcom ( including midcom itself ). This method also updates packages, so again , you may want to use it anywhere and as often as you need.
MIDGARD SETUP: net_nehmer_blog already installed
MIDGARD SETUP: Installing template_kubrick
warning: midcom/template_Kubrick requires package "midcom/fi.protie.navigation"
downloading template_Kubrick-1.0.4.tgz ...
Starting to download template_Kubrick-1.0.4.tgz (10,911 bytes)
Preferred state
You might also want to change pear's config preffered state.
$msp->set_state('beta');
Of course you should set this just after midgard_setup_pear object has been created.
I want more
So, when your script needs to install some midcom package, you just need to use __ install_midcom_package__ method.
$msp->install_midcom_package('net_nemein_reservations');
Keep in mind that this method also updates package if it's already installed and midcom channel provides newer one. You do not have to define channel here. midgard_setup_pear will do this especially for you.
There are things on heaven and earth....
Go to PEAR docs. Spent some time on reading them. If you find some method doc like this
void &someMthod($params);
do not wonder what this mehod returns. It just retuns void class instance... Yeah... void class....
midgard_setup_vhost
Posted on 2007-08-31 11:08:02 UTC.
Yeah, I was to blog about this one week ago, but we are going to have one vacation week so plenty of things must be done before it. Also me and Aga had no much possibilities to spend time together for last two years as she just finished logistic school ( yep , she also works ) and this summer we decided to spend every possible hour together :)
I mean, I just wanted to say I had no time to blog about midgard_setup_vhost ;)
OK, so here it is: midgard_setup_vhost.
Constructor
$vhost = new midgard_setup_vhost($&config, "www.site.com");
$config is an instance of midgard_setup_config, a simple class which holds reference to midgard_config , defined ui and similiar ones.
Set directories
$vhost->set_host_directories();
Creates all virtual host's directories like cache file or DocumentRoot. It is safe to call it as many times as you need, if one of te directories exist, vhost object will ignore it.
Enable Apache module
$vhost->enable_apache_module();
Checks if midgard apache module is included in configuration, and include it if it's not. It also creates midgard's httpd conf file and tries to detect if Apache is already listening on the host's port. If not , midgard's httpd conf file is edited to include Listen directive.
Create configuration
$vhost->create_configuration();
Creates configuration file and save it to default location. User defined one may be used if location parameter is passed to method.
This method internally uses midgard_setup_vhost_config class which is responsible to create nice and readable virtual host's configuration.
midgard_quick_setup
Posted on 2007-08-31 11:19:10 UTC.
The simplest and easiest midgard installation tool. The main idea is to act with default, sensible values and ask only mandatory questions.
To test it you must prepare for tricky builds.
Build midgard-core and midgard-php5 from 1-9 branch. Get all midgard_setup files from trunk.
The quickest setup is available in dg_quick.php script. Almost final script is available in midgard_datagard.php
"Almost final" means that this script must be wrapped by some shell script like datagard to allow transparently exit php script and start it again with quite different settings. Simple we can not load Mgdchema classes when php is running so we must quit itself and start itself again. Of course without asking the user :)
To make first initial midgard setup just do this:
php midgard_datagard.php
Certificate in Logistics
Posted on 2007-08-31 11:32:59 UTC.
I am very happy :). Aga has European Certificate in Logistics since today.
Let us know if she should send her CV :)