Convert Zend config from ini to yaml. Pitfalls
as a Preface I will say that I always like yaml. It so happened that I mostly work with Zend Framework But unfortunately ZF for a long time did not support yaml. Then I added a simple class which was a wrapper for the Symfony component, sfYaml and began slowly to use yaml in my projects.
Finally, in ZF 1.11.12 added Zend_Config_Writer_Yaml and I decided to convert the configs from ini to yaml.
Without thinking, I found on the Internet a ready script. Looked like this.
the
Alright, looks easy, uses only ZF classes, no Amateur — that's good. I try to convert. Everything turned out as it should. Ran the tests — everything works. Okay, now do the same on the battle server.
After a while we began to get an error from mysql General error: 1205 Lock wait timeout exceeded; I try to run just the query and run into Locke. Well watch SHOW PROCESSLIST and see nothing. It should be noted that there was only InnoDB tables, and 90-95% MyISAM. I googled a bit about this — we try to do the show engine innodb status. I see only the not started threads i.e. there is no transaction running, which could lochit other queries.
Trying to pull of the staff — nothing zanogo they are not learned. Proposed to add the indexes... well, you're in trouble.
Okay, it is necessary to do something. We recently started to use Gearman, respectively is sorcery, which are essentially demons, and open a long connection. Began to sin on them — let think will restart them. And helped Lok starred. But the reason is still not clear. Added privately commit after each task — like it quiet.
The next day, check the soap — same story. Periodically arrive similar faults.
Here so I want to ask who guessed what happened?
In the morning the managers complain that the client cannot update the info. Check — do the query there, and data is not changed. Then I remember about yesterday's COMMIT-s forced. Well, what the hell, let's try to do
show variables like “%autocommit%”;
Get ON all right, also most of their php and... drum roll OFF. (up to this point to admit of the staff remembered all the bad words, but is not to blame)
In the end, everything was easy and simple.
Taks... and how could that be all it worked, look in the configs and find out a minor little detail.
resources.multidb.dbname.adapter = “pdo_mysql”
resources.multidb.dbname.host = “localhost”
resources.multidb.dbname.username = “user”
resources.multidb.dbname.password = “pass”
resources.multidb.dbname.dbname = “dbname”
resources.multidb.dbname.driver_options.1002 = “SET NAMES utf8;”
converted
the
as you can see when converting 1002 became virtually 0. Then if you look a little deeper we will see
in Zend_Db
// PDO constant values discovered by this script result:
const ATTR_AUTOCOMMIT = 0;
...
And lastly the perpetratortriumph — Zend_Config_Writer_Yaml
the
I want to add that if you use SymfonyComponents/YAML/sfYaml.php that I mentioned at the beginning of the article (I wrote it och a simple wrapper for a convenient use in ZF) and add in our example
$writer->setYamlEncoder(array(‘App_Yaml’, ‘dump’));
all preconverted correctly.
So friends be careful when it comes to configs.
Do not judge strictly — the first a post on habré.
Article based on information from habrahabr.ru
Finally, in ZF 1.11.12 added Zend_Config_Writer_Yaml and I decided to convert the configs from ini to yaml.
Without thinking, I found on the Internet a ready script. Looked like this.
the
$inputfile = APPLICATION_PATH . '/configs/application.ini';
$outputfile = APPLICATION_PATH. '/configs/application.yml';
$config = new Zend_Config_Ini($inputfile, null, array('allowModifications' => false, 'skipExtends'=> true));
$writer = new Zend_Config_Writer_Yaml();
$writer- > write($outputfile, $config, true, true);
Alright, looks easy, uses only ZF classes, no Amateur — that's good. I try to convert. Everything turned out as it should. Ran the tests — everything works. Okay, now do the same on the battle server.
After a while we began to get an error from mysql General error: 1205 Lock wait timeout exceeded; I try to run just the query and run into Locke. Well watch SHOW PROCESSLIST and see nothing. It should be noted that there was only InnoDB tables, and 90-95% MyISAM. I googled a bit about this — we try to do the show engine innodb status. I see only the not started threads i.e. there is no transaction running, which could lochit other queries.
Trying to pull of the staff — nothing zanogo they are not learned. Proposed to add the indexes... well, you're in trouble.
Okay, it is necessary to do something. We recently started to use Gearman, respectively is sorcery, which are essentially demons, and open a long connection. Began to sin on them — let think will restart them. And helped Lok starred. But the reason is still not clear. Added privately commit after each task — like it quiet.
The next day, check the soap — same story. Periodically arrive similar faults.
Here so I want to ask who guessed what happened?
In the morning the managers complain that the client cannot update the info. Check — do the query there, and data is not changed. Then I remember about yesterday's COMMIT-s forced. Well, what the hell, let's try to do
show variables like “%autocommit%”;
Get ON all right, also most of their php and... drum roll OFF. (up to this point to admit of the staff remembered all the bad words, but is not to blame)
In the end, everything was easy and simple.
Taks... and how could that be all it worked, look in the configs and find out a minor little detail.
resources.multidb.dbname.adapter = “pdo_mysql”
resources.multidb.dbname.host = “localhost”
resources.multidb.dbname.username = “user”
resources.multidb.dbname.password = “pass”
resources.multidb.dbname.dbname = “dbname”
resources.multidb.dbname.driver_options.1002 = “SET NAMES utf8;”
converted
the
resources: multidb: dbname: adapter: pdo_mysql host: localhost username: user password: pass dbname: dbname driver_options: - SET NAMES utf8;
as you can see when converting 1002 became virtually 0. Then if you look a little deeper we will see
in Zend_Db
// PDO constant values discovered by this script result:
const ATTR_AUTOCOMMIT = 0;
...
And lastly the perpetrator
the
/**
* Service function for encoding YAML
*
* @param int $indent Current indent level
* @param array $data Data to encode
* @return string
*/
protected static function _encodeYaml($indent, $data)
{
reset($data);
$result = "";
$numeric = is_numeric(key($data)); // look here
foreach($data as $key => $value) {
if(is_array($value)) {
$encoded = "\n".self::_encodeYaml($indent+1, $value);
} else {
$encoded = (string)$value."\n";
}
$result .= str_repeat(" ", $indent).($numeric?"- ":"$key: ").$encoded; // and look here
}
return $result;
}
I want to add that if you use SymfonyComponents/YAML/sfYaml.php that I mentioned at the beginning of the article (I wrote it och a simple wrapper for a convenient use in ZF) and add in our example
$writer->setYamlEncoder(array(‘App_Yaml’, ‘dump’));
all preconverted correctly.
So friends be careful when it comes to configs.
Do not judge strictly — the first a post on habré.
Комментарии
Отправить комментарий