Search This Blog

Tuesday, February 23, 2010

PHP mail returns false on Fedora linux

While helping out a friend on a PHP installation, came across this issue.

Everything worked fine on his development server. But on his deployment server, the mail function returned false and hence no mails were sent out.

After some debugging found that the issue was with permission for httpd on sendmail.

vim /var/log/maillog had error NOQUEUE: SYSERR(apache): /etc/mail/sendmail.cf: line 0: cannot open: Permission denied

After spending some time on Google, came across this command.
# getsebool -a | grep sendmail
httpd_can_sendmail --> off

So the issue was that the apache user did not have permissions to send mails using sendmail.

Ran the following command
# togglebool httpd_can_sendmail

and everything worked fine.

Friday, February 12, 2010

Clone input element and add to hidden form using jQuery

If a file input element is placed in a form and you would like to upload it using a hidden form, the first thought would be


var file_elem = jQuery('#fileElem');
var cloned = file_elem.clone();

var hdn_frm = jQuery('#frm');
hdn_frm.append(cloned);

hdn_frm.submit();


This would work in firefox. But it would not work in IE.

Editing the file form field is a security risk and thus is disabled on most browsers.

A workaround would be:


var file_elem = jQuery('#fileElem');
var cloned = file_elem.clone();
cloned.id = 'fileElem1';
var hdn_frm = jQuery('#frm');

// Put the cloned element directly after the real element
// (the cloned element will take the real input element's place in your UI
// after you move the real element in the next step)
cloned.insertAfter(file_elem);
file_elem.hide();

file_elem.appendTo(hdn_frm);
hnd_frm.submit();


If you are using ajaxSubmit for form, in case error message is returned or if you stay on the form, the user could change the file being uploaded. Since the current element being seen is the cloned one, the desired result would not be achieved.

For this, after the form submit, reset the file elements.


var file_elem = jQuery('#fileElem');
var cloned = jQuery('#fileElem');

file_elem.insertBefore(cloned);
file_elem.show();
cloned.remove();

Rename Drupal core module tab titles

Drupal default user profile page shows tabs "View" & "Edit". If you want to add tab to the user profile page the original tabs could be confusing. Copy the following function to your custom module and it should rename the original tabs.


function user_menu_alter(&$items) {
$items['user/%user/view']['title'] = 'View Profile';
$items['user/%user_category/edit']['title'] = 'Edit Profile';
}


To remove tabs completely refer http://drupal.org/node/483324

Tuesday, February 02, 2010

HipHop for PHP: Move Fast

http://developers.facebook.com/news.php?blog=1&story=358

<CLIP>
With HipHop we've reduced the CPU usage on our Web servers on average by about fifty percent, depending on the page. Less CPU means fewer servers, which means less overhead.
</CLIP>
<CLIP>
HipHop for PHP isn't technically a compiler itself. Rather it is a source code transformer. HipHop programmatically transforms your PHP source code into highly optimized C++ and then uses g++ to compile it. HipHop executes the source code in a semantically equivalent manner and sacrifices some rarely used features - such as eval() - in exchange for improved performance. HipHop includes a code transformer, a reimplementation of PHP's runtime system, and a rewrite of many common PHP Extensions to take advantage of these performance optimizations.
</CLIP>

Interesting thing to observe here is that people find it less expensive (and quicker) to develope applications in 'simple' languages like PHP. For speed, rather than (mannually) porting application code which is expensive in terms of time and money (and also error prone), people prefer to change the runtimes, use automated porting (HipHop style) or even throw more hardware at it.

Slash doted at
http://developers.slashdot.org/story/10/02/03/003249/Facebooks-HipHop-Also-a-PHP-Webserver?art_pos=2

<Slashdot>
"As expected, Facebook today announced a new runtime for PHP, called HipHop. What wasn't expected were a few key revelationsdisclosed today by Facebook developer David Recordan. As it turns out Facebook has been running HipHop for months and it now power 90 percent of their servers - it's not a skunkworks project it's a Live production technology. It's also not just a runtime, it's also a new webserver. 'In general, Apache is a great Web server, but when we were looking at how we get the next half percent or percent of performance, we didn't need all the features that Apache offers," Recordon said. He added, however, that he hopes an open source project will one day emerge around making HipHop work with Apache Web servers.'"
</Slashdot>

Previous related news:
http://www.sdtimes.com/blog/post/2010/01/30/Facebook-rewrites-PHP-runtime.aspx

It would be interesting to see it's made available in open-source and can be applied to drupal.

<from slashdot>
Facebook has gotten fed up with the speed of PHP. The company has been working on a skunkworks project to rewrite the PHP runtime, and on Tuesday of this week, they will be announcing the availability of their new PHP runtime as an open source project. The rumor around this began last week when the Facebook team invited some of the core PHP contributors to their campus to discuss some new open source project.
</from slashdot>

Slash doted at
http://developers.slashdot.org/story/10/01/31/0252201/Facebook-Rewrites-PHP-Runtime-For-Speed?art_pos=14