Apr 14
HipHop is a tool that converts PHP code into C++ code that when combined with a PHP compatible engine and extensions library. According to Haiping Zhao (Developer at Facebook), It can speed up applications by 50%. Currently, Facebook is serving 90% of its Web traffic using HipHop.
Compiling PHP to C is not a new idea. There were some open source projects like PHC, Roadsend. However it seems that HipHop is the most ‘practical’ one among the others since it has been used to convert millions of lines of PHP in Facebook Server.
According to Facebook, the project was bridging the gap between PHP and C++ by static transformation. The transformation process includes three main steps:
1. Static analysis
2. Type inference
3. Code generation
The main step that they gain performance is type inference since PHP is a weakly typed language. When the variables are converted to corresponding specific types in C++, they require less memory.
There are some drawbacks that you need to consider before using HipHop in your porjects:
1- PHP 5.3 is not supported by HipHop. So, for now, forget about namespaces, late static binding if you decide to use HipHop.
2- Some functions like ‘eval()’ is not supported.
3- If you’re using PHP extensions that is not included in HipHop project, you need to convert them to C++ variants
4- If you’re a ‘PHP on Windows’ fan, you need to reconsider this since it doesn’t work on windows.
Check out HipHop wiki page for installation instructions and source code.
http://wiki.github.com/facebook/hiphop-php/
Tagged with: C • compile PHP to C++. C++ • hiphop
Mar 11
Although some of the differences are outdated, here is a very useful blog post comparing Amazon’s SimpleDB with couchDB:
http://www.automatthew.com/2007/12/amazon-simpledb-and-couchdb-compared.html
Tagged with: couchDB • database • simpleDB
Mar 09
PUT
- It is used to create new resource or overwrite it.
PUT /(action)/ HTTP/1.1
Host: example.com
will create a new resource. Similarly,
PUT /(action)/ HTTP/1.1
Host: example.com
will update your existing resource.
POST
- It is used to update (overwrite) an existing resource
POST /(action)/ HTTP/1.1
Host: example.com
will modify your resource. However,
POST /(action)/ HTTP/1.1
Host: example.com
will return a ‘resource not found’ error.
For more information visit W3.org
Tagged with: HTTP • POST • POST vs PUT • PUT • RESTful
Jan 18
There are several ways of renaming files if you don’t want to use Zend_Form_Element component. However, the following is a ZF technique.Suppose you have a very basic form with a single file element:
Form.php
class My_Form extends Zend_Form
{
public function init()
{
$element = new Zend_Form_Element_File('imagefile');
$element->setLabel('Upload an image:');
$element->setDestination($uploaddir); /* file directory */
$element->addValidator('Count', false, 1);
$element->addValidator('Size', false, 202400);
$element->setRequired(false);
$element->addValidator('IsImage', false, 'jpeg,jpg,png,gif');
$this->addElement($element, 'imagefile');
}
}
What you need to do is to override the isValid( .. ) method of your Form Object:
Form.php
public function isValid($data) {
$oldname = pathinfo($this->imagefile->getFileName());
$newname = $this->getUniqueCode(10) . '.' . $oldname['extension'];
$this->imagefile->addFilter('Rename',$newname);
return parent::isValid($data);
}
If you don’t want to loose your other validators , don’t forget to call the parent isValid() method . As you can see, I used PHP’s pathinfo() method to parse the file path. (There should be another one in ZF ). I renamed it with a string of 10 random characters, and kept the extension as it was. Below is the method that you can use for the random file name :
function getUniqueCode($length = "") {
$code = md5(uniqid(rand(), true));
if ($length != "")
return substr($code, 0, $length);
else
return $code;
}
Finally, in your controller, you basically check if the form is valid,
MyFormController.php
$request = $this->getRequest();
$form = new My_Form();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
$formData = $form->getValues();
try {
$form->imagefile->receive();
} catch (Exception $e) {
throw new Zend_Exception ('There is a problem with the file upload');
}
}
}
I hope it helps.
Tagged with: file • isvalid • pathinfo • rename • Zend_Form • Zend_Form_Element_File
Jan 18
A good blog post about an advantage of Doctrine over Zend_Db_Table:
http://roetgers.org/2009/10/21/why-i-prefer-propel-over-zend_db_table/