Archive for the ‘web development’ Category
Compile your PHP code
Facebook shared their PHP to C++ code translator called HipHop that opens up a possibility to compile your code using gcc. Facebook reports that it can fasten up your code up to 50%. Moreover, it’s free!
However, HipHop has it’s drawbacks (some of the are good features, not drawbacks):
- No Windows support (great!)
- No eval() and create_function() support (that’s also great)
- Lots of modules are unsupported at the moment
- Some other minor drawbacks (e.g. function_exists() might not work the way you expect it to work)
In any case – it is worth a try. Grab HipHop here.
Some analytics on HipHop from Marco Tabini, Ilia Alshanetsky
Did you hide your SVN?
If you use SVN on your development or production server, try and add “/.svn/entries” to your website root, so the URL would look like this http://yoursite.com/.svn/entries (note the absence of the trailing slash).
Those who aware of the possible outcomes of letting svn resources be accessible from the Internet can skip this post. Others using SVN, be aware.
Using the .svn resources exposed to the world, I can get such information as the repository address (in conjunction with other data, it’s likely to have a working copy of the repo), developers login, corresponding deployment information, etc.
The problem is very common and you can even try to steal valuable information from leaders of the industry ( the first one that comes to my mind is classmates.com – .svn resources are open at the time of writing this post). Moreover, there are web-sites on the Internet that allow anonymous checkout of their own code.
The problem can be solved within 5 minutes and the recipe is widely-known ( check out google results ).
CakePHP schema TIMESTAMP field create error solution
What a dissapointment! CakePHP schema generation feature does not handle DB TIMESTAMP fields default values correctly. While we wait for the official fix, we can use a quickfix for the issue.
The code responsible for column creation is in the cake/libs/model/datasources/dbo_source.php file. Scan for the “function buildColumn()”. The particular place where default DB fields values are handled is this:
if (($column['type'] == 'integer' || $column['type'] == 'float' ) && isset($column['default'])
&& $column['default'] === '') {
$column['default'] = null;
}
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
$out .= ' ' . $this->columns['primary_key']['name'];
} elseif (isset($column['key']) && $column['key'] == 'primary') {
$out .= ' NOT NULL';
} elseif (isset($column['default']) && isset($column['null']) && $column['null'] == false) {
$out .= ' DEFAULT ' . $this->value($column['default'], $type) . ' NOT NULL';
} elseif (isset($column['default'])) {
$out .= ' DEFAULT ' . $this->value($column['default'], $type);
} elseif (isset($column['null']) && $column['null'] == true) {
$out .= ' DEFAULT NULL';
} elseif (isset($column['null']) && $column['null'] == false) {
$out .= ' NOT NULL';
}
return $out;
Our fix will be as simple as it can be yet it will serve the purpose of correct column generation. Let's see what we can do:
if (($column['type'] == 'integer' || $column['type'] == 'float' ) && isset($column['default'])
&& $column['default'] === '') {
$column['default'] = null;
} elseif ($column['type'] =='timestamp' && $column['default'] != 'CURRENT_TIMESTAMP') {
$column['default'] = '2000-01-01 00:00:00';
}
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
$out .= ' ' . $this->columns['primary_key']['name'];
} elseif (isset($column['key']) && $column['key'] == 'primary') {
$out .= ' NOT NULL';
} elseif (isset($column['default']) && isset($column['null']) && $column['null'] == false) {
if ($column['type'] == 'timestamp' && $column['default']=='CURRENT_TIMESTAMP'){
$out .= ' DEFAULT CURRENT_TIMESTAMP NOT NULL';
} else {
$out .= ' DEFAULT ' . $this->value($column['default'], $type) . ' NOT NULL';
}
} elseif (isset($column['default'])) {
$out .= ' DEFAULT ' . $this->value($column['default'], $type);
} elseif (isset($column['null']) && $column['null'] == true) {
$out .= ' DEFAULT NULL';
} elseif (isset($column['null']) && $column['null'] == false) {
$out .= ' NOT NULL';
}
return $out;
}
Actually, we added a trick for all the next timestamp fields (except the one with CURRENT_TIMESTAMP default value) to have arbitrary not NULL default values.
Another trick is to have CURRENT_TIMESTAMP default value unquoted by CakePHP schema code (which actually prevents the schema script from running).
Tricks above are pretty dumb, but I’d not bother with the perfect solution as we’re going to have one from “the clean IP” really soon (I hope).