something regarding programming and installations...
Human knowledge belongs to the world!
Wednesday, June 09, 2010
Showing tabs of open sessions in screen
It is very useful when you are working on a remote machine through ssh.
More info about screen at: https://help.ubuntu.com/community/Screen
But it could be quite irritating when you have multiple sessions open and you have to cycle through them frequently since there are no tabs or status bar.
But, there is a solution for the same :)
Edit /etc/screenrc or ~/.screenrc and add the following line. Then start screen.
caption always '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %D %Y-%m-%d %c:%s %{g}]'
Tuesday, February 23, 2010
PHP mail returns false on Fedora linux
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
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
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
<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
Saturday, January 30, 2010
How to check if an element is in current viewport of webpage using jQuery
jQuery(window).scrollTop() > $elem.offset().top
checks if the element has been scrolled up.
($elem.offset().top + $elem.height()) > jQuery(window).height()
checks if the element is below the current view port.
If any of the conditions is true, the element is currently not visible completely.
You can bring it in view using
jQuery('html,body').animate({scrollTop: $elem.offset().top}, 500);
Monday, October 12, 2009
Adding BackLinks in Trac wiki
A workaround for the same is installing external macros from trac-hacks.org.
You could use following two macros
http://trac-hacks.org/wiki/BackLinksMacro (Adds textual info at the top of page)
http://trac-hacks.org/wiki/BackLinksMenuMacro (Adds a menu to top RHS like pageoutline macro)
Download the zip from the site. Extract it to some temp location.
Check your trac version(click on "about trac" link).
Copy the BackLinksMenu.py/ BackLinks.5.py(rename to BackLinks.py) from the correct version folder to /usr/share/trac/wiki-macros/
Restart apache and you are done.
Sunday, July 26, 2009
India Biodiversity Portal
Sunday, May 24, 2009
PHP
PHP
What is PHP?PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
PHP is now officially known as PHP: HyperText Preprocessor. It is a server-side scripting language usually written in an HTML context. Unlike an ordinary HTML page, a PHP script is not sent directly to a client by the server; instead, it is parsed by the PHP binary or module. HTML elements in the script are left alone, but PHP code is interpreted and executed. PHP code in a script can query databases, create images, read and write files, talk to remote servers— the possibilities are endless.
The output from PHP code is combined with the HTML in the script and the result sent to the user.
PHP was created for the web - PHP started as a collection of C applications that
the author wrote for use on his own web site. It evolved into a server-side
scripting language built for building logic into web pages. This
single-mindedness in design has resulted in a language that is both flexible and
streamlined for use on the web.
Finally, it is OPEN SOURCE.
Popularity:
- According to NetCraft (http://www.netcraft.com), PHP was running on more than 1 million hosts in November 1999. As of February 2000, that figure had already risen to
1.4 million hosts. - According to E-Soft, PHP is the most popular Apache module available, beating even ModPerl.
- Visit http://www.php.net/usage.php to check how popular PHP is!
* Learning Curve:
- of both the languages and the framework/tools
- Assuming that the developer is only familiar with a basic language like C / C++ that is taught in most academia
PHP's syntax is fairly like C.
- Function calls are "function_name()"
- Lines end in semicolons
- Whitespace is mostly insignificant
- "if", "for", "while" and "switch" syntax is pretty much the same
- Most of the mathematical, boolean, assignment and comparison operators are the same
The biggest difference in syntax is that variables in PHP always begin with a dollar sign, e.g. $foo.
However, PHP is a much higher level language than C. You rarely need to worry about casting variables to a different type, and never have to deal with pointers. Strings are a basic data type in PHP, and don't need to be treated as an array of characters. Indeed, there isn't a character data type -- characters are just strings with length 1.
PHP has a lot more functions built in to the language, compared to C where a lot of functionality (e.g. database connectivity, regular expressions, networking functions) needs to be imported through libraries.
PHP4 has a certain amount of OO support, and PHP 5 has almost as much OO support as Java does.
The learning curve for PHP is very fast.
http://php.net/quickref.php has information about all PHP functions. The docs have various examples and user submitted examples.
The only concern is understanding the nuances of HTML & CSS.
Things to focus on from the start:
- Understand HTML forms
- Understand how PHP receives information (superglobal $_GET[] and $_POST[]) from the forms.
* IDE / Editor Support:
PHP code can be written in ANY text editor, even simple editors like notepad. But for faster developments, IDEs are a better option.
IDEs usually provide features like:
- Syntax highlighting: Good syntax highlighting improves code readability a lot.
- Code completion: Automatic code suggestions can help the developer avoid having to type so much. If it supports custom classes and phpDoc, it can even save you from having to read project documentation. Good code completion can also prevent typos.
- Navigation: One of the most boring things is trying to find where a certain variable has been defined or used. Some good IDEs can help with “GoTo” actions, like go to definition.
- Errors and warnings highlighting: On-the-fly syntax checking can prevent various typos and common programming mistakes.
- Debugging: Debugging is not so critical in PHP because you can add echos or use something like FirePHP without even having to recompile your code. But for complex applications in which you need to add echo after each line to see what’s going on, debugging can save you hours.
- Client-side features: Using PHP alone is very rare. CSS and JavaScript are almost always somewhere in your application. So, good code completion, highlighting, navigation and perhaps some refactoring would be just as beneficial for the other languages and technologies you use in conjunction with PHP.
Every IDE provides a lot of features. Some of those features are very useful, some are not. Here are some guidelines to follow to narrow down the one for you:
- Try free ones first. Their feature set may be enough for you, and you wouldn’t need to pay for a license.
- First, make sure the features you want are ones you really need. If they are, check that they work properly in your IDE of choice.
- If you find one IDE that fits well but is missing one or two features, try specialized tools.
- Once you choose an IDE, play with it for a week before implementing it in a big project. You may find your current working habits are too strong to allow you to feel comfortable with it.
- http://www.smashingmagazine.com/2009/02/11/the-big-php-ides-test-why-use-oneand-which-to-choose/
- http://spreadsheets.google.com/ccc?key=pV8XyUSUOM7ET07rn4n7NYA
- Compiled languages usually involve a "build" step that can slow down development time.
Because PHP allows the separation of HTML code from scripted elements, there is a significant decrease in development time on many projects. In many instances, the coding stage of a project can be separated from the design and build stages. Not only can this make life easier for a programmer, it also can remove obstacles that stand in the way of effective and flexible design.
- Amount of code needed to achieve same functionality could be different for different frameworks/languages
PHP provides many basic functions allowing programmers to just focus on the logic rather than implementing minor functions. It has a HUGE amount of useful functions (graphic, texts, database, ports,
mailing, encryption and so on).
Also, PHP has frameworks like PEAR and PECL which provide various libraries for better and faster development.
The only concern is for developers who come from .NET background. They are used to drag-drop UI elements, while PHP does not have a built in support for direct UI elements. But since PHP supports OOPs, classes can be written for UI elements which are required very often.
* Library/Framework support for:
- Authentication / Authorization:
PHP has a very good framework and distribution system for reusable PHP components called PEAR - PHP Extension and Application Repository. PEAR has various authentication and authorization libraries.
There are also lot of opensource user submitted libraries which could be selected based on specific requirements.
- ORM / DB support (connection pooling, caching, etc):
PHP does not support connection pooling. The problem is that traditionnaly, PHP is used for “read-more, write-less”
kind of application. Meaning MySQL/MyISAM whithout transaction support. In this
case, the connection cost is low and isn't noticable.
PHP does support persistent connections. Persistent connections are links that do not close when the execution of the script ends. When a persistent connection is requested, PHP checks if there's
already an identical persistent connection (that remained open from earlier) -
and if it exists, it uses it. If it does not exist, it creates the link.
- ORM:
Database Extensions(PHP has built in support for various databases):
- Abstraction Layers
- Vendor Specific Database Extensions
- dBase
- DB++
- FrontBase
- filePro
- Firebird/InterBase
- Informix
- IBM DB2 — IBM DB2, Cloudscape and Apache Derby
- Ingres — Ingres DBMS, EDBC, and Enterprise Access Gateways
- MaxDB
- Mongo
- mSQL
- Mssql — Microsoft SQL Server
- MySQL
- Mysqli — MySQL Improved Extension
- OCI8 — Oracle OCI8
- Ovrimos SQL
- Paradox — Paradox File Access
- PostgreSQL
- SQLite
- SQLite3
- Sybase
- dBase
- Abstraction Layers
- MVC:
Top 10 PHP MVC Frameworks based on users reviews:
- Symfony: Based on Mojavi and inspired by Rails
- Mojavi: The first MVC framework I fell in love with
- CakePHP: Inspired by Rails PHP4/5
- PHPOnTrax: a Rails port - PHP5 Only
- Prado: The winner of Zend coding contest
- Studs: A Java-Struts port to PHP
- Phrame: A Java-Struts port
- Achievo: A good RAD framework
- WACT: Web Application Component Toolkit
- Ambivalence: A Java-Maverick Port
- AJAX / RPC:
- Sajax: Sajax is an open source tool to make programming websites using the Ajax framework — also known as XMLHTTPRequest or remote scripting — as easy as possible. Sajax makes it easy to call PHP, Perl or Python functions from your webpages via JavaScript without performing a browser refresh. The toolkit does 99% of the work for you so you have no excuse to not use it.
- Xajax: xajax is an open source PHP class library that allows you to easily create powerful, web-based, Ajax applications using HTML, CSS, JavaScript, and PHP. Applications developed with xajax can asynchronously call server-side PHP functions and update content without reloading the page.
- Cake PHP: Cake is a rapid development framework for PHP which uses commonly known design patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility.
- Saja: Saja is a lightweight, open-source AJAX scripting engine for PHP4/5, with optional secured data transfer. It is designed for the speedy creation of simple, secure, and maintainable AJAX applications, without the need to write any JavaScript.
- Ajason: PHP 5 library and JavaScript client for AJAX. Fetch data asynchronously and develop interactive GUI-like Web applications. Call PHP functions and object methods from JavaScript and exchange even complex data types between client and server.
A list of various other AJAX libraries can be found at http://ajaxpatterns.org/PHP_Ajax_Frameworks
- Inversion of Control
- Aspect oriented programming
* Performance:
- CPU and Mem requirements
- Multi threading support
- involves app boot/load time ( Time needed to start the app ) too.
PHP by its nature is one of the fastest web scripting languages available, having been more or less written for mod_php, the Apache module used for most PHP installations. Unlike Java, PHP is sufficiently dynamic to run literally as lightweight as you require - for example, you could write a web service in just ten lines of code that could easily handle millions of hits a day, as opposed to the overhead of pulling in a significant chunk of enterprise-sized libraries
that you probably don't need.
Because of the powerful Zend engine, PHP compares well with ASP in benchmark tests, beating it in some tests. Compiled PHP leaves ASP far behind.
The syntax is based on C - Being based on C makes it easier for Java, C, even Javascript programmers to pick up.
One feature of the language where it breaks from the C syntax is it’s object-oriented nature. It supports the creation of custom classes and allowing other classes to inherit from your custom classes. Future releases should futher enhance it’s object-oriented capabilities.PHP is much
faster than CGI - It’s not as fast as JSP’s, which are compiled, but it is faster and uses less system resources than CGI programs do.
PHP code run faster because there is no overhead of communicating with different COM objects
* Scalability:
PHP is highly scalable. Here are a few links which support this:
- http://www.onjava.com/pub/a/onjava/2003/10/15/php_scalability.html
- http://www.sitepoint.com/blogs/2004/07/02/why-php-scales/
* Security:
http://www.php.net/manual/en/security.php
PHP is a powerful language and the interpreter, whether included in a web server as a module or executed as a separate CGI binary, is able to access files, execute commands and open network connections on the server. These properties make anything run on a web server insecure by default. PHP is designed specifically to be a more secure language for writing CGI programs than Perl or C, and with correct selection of compile-time and runtime configuration options, and proper coding practices, it can give you exactly the combination of freedom and security you need.
As there are many different ways of utilizing PHP, there are many configuration options controlling its behaviour. A large selection of options guarantees you can use PHP for a lot of purposes, but it also means there are combinations of these options and server configurations that result in an insecure setup.The configuration flexibility of PHP is equally rivalled by the code flexibility. PHP can be used to build complete server applications, with all the power of a shell user, or it can be used for simple server-side includes with little risk in a tightly controlled environment. How you build that environment, and how secure it is, is largely up to the PHP developer.
* Code Maintenance:- Object Oriented / Functional / Procedural - Statically/Dynamically typed
Low maintenance and development cost.
Dynamically typed.
Supports both functional as well as OOPs. So easy code maintainability.
* Testing support:
- Unit , Performance, stress testing,etc
- Amock
- Description: Amock is a mock object library written in PHP 5, inspired by EasyMock. Mock objects for classes or interfaces are generated on the fly using a source code generator.
- Requirement: POSIX
- izh_test
- Description: izh_test is a xUnit-like framework which allows users to test php pages using the console version of php, uses file compare for checking results of tests, and can test session state content and db state content too
- Requirement: Windows
- PHP Assertion Unit Framework
- Description: Unit testing framework based on assertions which helps PHP developers test their code. Failing assertions about the program state are tracked in a Reporter window of a DOM-compliant browser such as IE5+, Mozilla, Netscape 6+, etc.
- Requirement: tbc
- PHPUnit
- Description: Unit testing framework for PHP based on the "JUnit" framework for Java. PHPUnit is a family of PEAR packages (PHPUnit2 for PHP 5, PHPUnit for PHP 4) that supports the development of object-oriented PHP applications using the
concepts and methods of Agile Software Development, Extreme Programming, Test-Driven Development and Design-by-Contract Development by providing an elegant and robust framework for the creation, execution and analysis of Unit Tests. - Requirement: OS Independent, PHP
- SimpleTest
- Description: Unit testing, web testing and mock objects framework for PHP. Additional features are generation of server stubs, integration of PhpUnit and PEAR test cases, on-line tutorials and documentation. The web testing won't be fully
finished until version 1.0, but the other functionality is stable. - Requirement: PHP
- Spike PHPCheckstyle
- Description: Spike PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions. The tools checks the input PHP source code and reports any deviations from the coding convention.
- Requirement: PHP 5.0 and newer
- Spike PHPCoverage
- Description: Spike PHPCoverage is an open-source tool for measuring and reporting code coverage provided by the test suite of a PHP application. Spike PHPCoverage can instrument and record the line coverage information for any PHP script at runtime.
- Requirement: PHP
- Testilence
- Description: Testilence is a unit-testing library for programs written in PHP 5. Although it is similar to other JUnit-inspired unit testing libraries, Testilence is
written with an emphasis on what is useful, not what is usual. That said, most
clever ways of doing useful things for unit test authors and users have already
been discovered. Testilence combines original ideas with the best features found
in different unit-testing toolkits into a coherent set. - Requirement: POSIX
- Object Oriented / Functional - Statically/Dynamically typed
- It has a HUGE amount of useful functions (graphic, texts, database, ports, mailing, encryption, regular expressions, XML parsing, cryptography and so on). You can compile in different libraries that allow you to manipulate graphics.
- It’s cross-language - What does that mean? It’s a term I
coined to show that PHP can use objects in languages other than PHP. It can
call Windows COM objects and Java objects, making it easier to separate the
business logic from the user interface. The PHP team is
even working on letting it call .NET assemblies. - Dynamically typed.
- Supports both functional as well as OOps.
- Ability to embed into HTML code
- Dev / Test / Production node deployments
- Hot deployment supported ?
PHP is designed to run on many operating systems and to cooperate with many servers and databases. You can build for a UNIX environment and shift your work to NT without a problem. You can test a project with Personal Web Server and install it on a UNIX system running on PHP as an Apache module.
* Web server support:
Compatible with servers IIS and Apache
* OS level support:
- e.g Even though there is Mono, newer Microsoft technologies may not available on other OSs.
- newer frameworks might not have good performance/support for all OSs
It’s cross-platform - PHP runs on UNIX, Linux, Mac OSX, and Windows.
* Community / Eco system:
- around the framework & language
- size & helpfulness
http://www.php.net/support.php
- It is maintained by an excellent team at www.php.net.
- Bugs are usually resolved in days.
- The Php community is adding features all the time, experienced programmers report problems, give solutions to difficult pieces of code and so on.
- Another reason for choosing PHP over other languages has to do with the popularity of the languages. Thousands of web pages are running PHP and it has a dedicated following. If you choose to learn PHP, you can be assured that you can find enough resources to answer any question you have and in most cases you’ll find that someone has already written code that does exactly what you need and is giving it away for free.
http://bogambilya.asti.dost.gov.ph/manual/en/faq.languages.php
Taking a look at PHP 6
While most web hosts are still in the PHP 4 era, the PHP developers are
already planning and working on PHP 6. Lets have a look at whats been keeping
them busy.
When youre creating a website, you hardly have to think about the character
encoding. You only have to decide how you tell the user agent what
encoding youre using, but with a little help of Apaches .htaccess file [slashdot.org], you only have to make that
decision once. However, if youre building an application, the character encoding
might become a problem. Thats where PHPs new Unicode support comes in handy.
With its support, PHP can automatically encode and decode the in and output of
the script making sure both the database and the user agent receive the encoding
they need without the need of any extra functions for the encoding
conversion.
PHP is already being used for a long time, creating a big user base, but also
a lot of bad habits. Bad habits often result in slow scripts or even security
holes. But these bad habits are not always the cause of the developer. Of
course, he (lets just assume were dealing with a stereotype developer here for
simplicity's sake) is the one whos using it in his application, but sometimes
the developer is not even aware hes using it.
Im, of course, talking about the register_globals [php.net], magic_quotes [php.net] and safe_mode [php.net] functions. These three functions
are hell for every PHP programmer so Im sure everyone will be happy to hear that
these functions will disappear in PHP 6.
In other related cleanup news, register_long_arrays and the long
versions of the super globals like $HTTP_COOKIE_VARS are also gone in
PHP 6. Same goes for zend.ze1_compatibility_mode which dealt with the
backwards compatibility of PHP 5 classes.
Caching is a very good way to improve the performance of an application.
Thats why there was a large demand for a good opcode cache in the default
distribution of PHP. And when theres a demand, theres probably also a person or
a group to meet that demand. The result is APC [php.net]:
Alternative PHP Cache. Of course, APC was already available a long time ago
(01-07-2003), but the PHP developers have decided to include this extension in
the core as the default caching framework.
The improved OO model was probably the biggest improvement to PHP in version
5.0. PHP 6 tries to improve this even further by adding namespaces. If youre
familiar with XMLs namespaces or maybe C++, you will probably have an idea of
how namespaces work. If not: Namespaces can group variables, functions or
objects under a certain name. This allows the developer to use the same name for
a variable, function or object multiple times. In case youd like to learn more
about the possibilities of namespaces, I find this C++
tutorial [cplusplus.com] about namespaces quite useful.
extensions
PHP is basically a collection of extensions which are all put together to
form what we have now. However, these extensions change and so does the
collection. Take, for instance, the XML Writer extension. A great extension to
write XML files. Its brother, XML Reader, was already added and enabled in the
core distribution in PHP 5.1, and now XML Writer will follow its example in PHP
6, forming a great duo to easily work with XML files.
Another change in the core distribution is the removal of the ereg regular
expressions library which is going to be made an extension. ereg is currently
used as an competitor of PCRE (preg_match, etc.), but apparently its
causing some problems. Therefore, the developers decided to remove it from the
core and make it an extension.
Yet another change we see is the Fileinfo extension which will be dealing
with media type detection. At the moment, media type detection isnt very good in
PHP. We have the mime_magic [php.net] extension, but that isnt really reliable.
So in PHP 6, the Fileinfo extension will take over mime_magics place and become
part of the core while mime_magic will be moved from the core and made into an
extension.
So weve seen quite some interesting changes so far. To me, PHP 6 doesnt
really look like a massive feature update, but more as a big cleanup while
improving a lot of existing functions along the way. And I think thats good! Im
working with PHP on an almost daily basis and looking at the things noted above,
Im only seeing improvements. So hopefully developers of popular applications
like phpBB
[phpbb.com] will make their applications work properly on PHP 5 making it easier
for web hosts to switch their servers to PHP 5. But at the current state of PHP
5 support, I dont see PHP 6 becoming widely adopted if it were released today.
So hopefully this will change by the time PHP 6 will be released.
For all the planned changes to PHP 6 (including the ones I noted above),
check out these meeting notes
[php.net].
http://www.corephp.co.uk/archives/19-Prepare-for-PHP-6.html
Wednesday, May 20, 2009
PHP Accelerators - APC
- http://in2.php.net/manual/en/book.apc.php
- http://docs.moodle.org/en/Installing_APC_in_Windows#Installation_on_Windows_Server
Packages:
- http://pecl.php.net/package/apc
- DLL for windows: http://dllcentral.com/php_apc.dll/5.2.5.5/ (Verify the version. It is available by default with wampserver 2)
PHP accelerators
- http://itst.net/wp-content/uploads/2006/10/PHP%20Bytecode%20Cacher%20Review.html
- http://blog.digitalstruct.com/2007/12/23/php-accelerators-apc-vs-zend-vs-xcache-with-zend-framework/
Users reviews:
- http://agilewebmasters.com/robert/what-is-the-best-php-accelerator-to-use/
- http://stackoverflow.com/questions/721600/php-accelerator-review
Thursday, December 04, 2008
Cheatsheets
Monday, November 10, 2008
Javascript Linkize using jQuery
Here is a code to linkize text within an HTML node.
Pass a HTML element as parameter to the function.
It will parse the text, search for all urls and convert them to html links.
This is not the best method though. Still working on it.
/* Author: Viraj Kanwade */
/* Parameter: the root element under which all HTML is to be linkized. */
/*
The function parses child elements of root element.
If the child node is an anchor, ignore it.
If the child node is text element, getLinks function is called
which parses HTML text and generated links.
If the child node is any other node, the linkize function is called
recurrsively.
*/
function linkize(root_elem) {
var elems = jQuery(root_elem).contents().not(jQuery("a"));
var len = elems.length;
for(var i=0; i < len; i++) {
var elem = elems[i];
if(elem.nodeType == 3) {
/* TODO: use regex
var url_match = /https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/;
var m = url_match.exec(elem.textContent);
console.log(m);
*/
jQuery(elem).replaceWith(genLinks(elem.textContent));
} else if(elem.tagName != "A") {
linkize(elem);
}
}
}
/* Function to parse HTML text and convert URLs in text to HTML links */
/* Author: Viraj Kanwade */
/* Parameter: HTML text to be parsed */
/* Returns: HTML text which has been linkized */
/*
The function searches for URLs in the text provided. If no URL is found,
it returns the original text. If a URL is found, it is linkized and the
remaining string is passed recurrsively to the function.
*/
function genLinks(txt) {
var http = "";
var pos = -1;
var pos1 = txt.indexOf("http://"); //get the first occurrence of HTTP:// in text
var pos2 = txt.indexOf("https://"); //get the first occurrence of HTTPS:// in text
var pos3 = txt.indexOf("www."); //get the first occurrence of WWW. in text
// find which of the three occurs first
if(pos1 > -1) {
pos = pos1;
}
if(pos2 > -1) {
if(pos == -1) {
pos = pos2;
} else if (pos2 < pos) {
pos = pos2;
}
}
if(pos3 > -1) {
if(pos == -1) {
pos = pos3;
} else if (pos3 < pos) {
pos = pos3;
}
http = "http://"; // since HTTP:// is missing from the URL (www.), it needs to be added in anchor.
}
if(pos != -1) { // URL found
var txt2 = txt.substring(0, pos);
pos1 = txt.indexOf(" ", pos); // Space is assumed to be the delimiter for URL
if(pos1 == -1) {
pos1 = txt.indexOf(String.fromCharCode(160), pos);
}
if(pos1 == -1) { // If space is not found, it can be assumed that it is the end of text.
var txt3 = txt.substring(pos);
txt2 += '<a href="' + http + txt3 + '" target="_blank">' + txt3 + '</a>';
} else {
/*
Space is found. So it can be assumed that there is more text. Linkize the URL extracted and
pass the remaining text for a recurrsive call to the function.
*/
var txt3 = txt.substring(pos, pos1);
txt2 += '<a href="' + http + txt3 + '" target="_blank">' + txt3 + '</a>';
txt2 += genLinks(txt.substring(pos1));
}
return txt2; // Return linkized text.
} else { // No URL found in text. Return original text.
return txt;
}
}
jQuery Linkize Plugin
Monday, June 30, 2008
Javascript XML Parsing
function getXMLDocObject(xmlstr) {
var xmlDoc;
try { //Internet Explorer
try {
xmlDoc=new ActiveXObject("MSXML2.DOMDocument");
} catch(e) {
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
xmlDoc.async="false";
xmlDoc.loadXML(xmlstr);
} catch(e) {
try { //Firefox, Mozilla, Opera, etc.
parser=new DOMParser();
xmlDoc=parser.parseFromString(xmlstr,"text/xml");
} catch(e) {
alert(e.message)
}
}
return xmlDoc;
}/* Consider the following XML
*/
<?xml version="1.0" encoding="utf-8"?>
<rootnode>
<error value='true'>
<message>this is the message</message>
</error>
</rootnode>
// Create XMLDoc object
xmlDoc = getXMLDocObject(asyncreq.responseText);
// Get root node
var root = xmlDoc.getElementsByTagName('rootnode')[0];
/* You can loop over all child nodes of root using root.childNodes and root.childNodes.length */
// Will alert "error"
alert(root.childNodes[1].nodeName);
// Will alert "true";
alert(root.childNodes[1].getAttribute('value'));
// Will alert "message";
alert(root.childNodes[1].childNodes[1].nodeName);
// Will alert "this is the message".
alert(root.childNodes[1].childNodes[1].childNodes[0].nodeValue);
Thursday, April 05, 2007
Debug javascript object
var obj = [object to debug]
var temp = "";
for (x in obj)
{
temp += x + ": " + obj[x] + "\n-----\n";
}
alert (temp);
Thursday, June 15, 2006
HTML - change the way links look
The A:hover tells the browser that when the mouse is over a link the underline should appear.
The hover option only works on MSIE 4+.
(But it does not cause an error on Netscape if you include it - the effect just does not appear.).
<html>
<head>
<title>This is my page</title>
<style type="text/css">
<!--
A:link {text-decoration: none}
A:visited {text-decoration: none}
A:active {text-decoration: none}
A:hover {text-decoration: underline}
-->
</style>
</head>
<body>
Welcome to my world!<br>
<a href="http://viraj-workstuff.blogspot.com/">This Link To My Blog has no underline</a>
</body>
</html>
If you want to turn off the effect for just a single link, add a style property to the <a href> tag:
<a href="http://viraj-workstuff.blogspot.com/" style="text-decoration: none">Go to my blog</a>
You can make multiple style settings instead of just removing the underline.
<html>
<head>
<title>This is my page</title>
<STYLE TYPE="text/css"><!--
A.set1:link {color: #FF00FF; }
A.set1:active {color: #FFFF00; }
A.set1:visited {color: #00FFFF; }
A.set2:link {color: #AA00FF; background: FF00AA; text-decoration: none}
A.set2:active {color: #FF00AA; background: none transparent;}
A.set2:visited {color: #FFFF00; text-decoration: none}
--></STYLE>
</head>
<body>
Welcome to my world!<br>
<a href="http://viraj-workstuff.blogspot.com/" CLASS=set1> My Blog </a>
<a href="http://www.blogger.com/profile/10381021" CLASS=set2> My Profile </a>
</body>
</html>
Wednesday, February 15, 2006
Converting win XP to linux
Multiple workspaces: You miss this feature when you are working on different projects and you see all the windows in the same workspace. You find it difficult to find the project specific window. You just wish there were workspaces where you could group together the windows and put them in different workspaces. Dont worry, you have a solution though not exactly similar to linux. Thank you Virtual Dimension.
Multiple Panels: For people used to multiple launch panels, ObjectDock.
Sunday, January 15, 2006
Upgrading to firefox 1.5
The Totem video plugin doesn't seem to work with firefox 1.5
Install package 'mozilla-mplayer' instead.
Also you need package 'libstdc++5' installed.
You may get an error dialog (twice) each time Firefox starts up saying Firefox could not install this item because of a failure in Chrome Registration.
This is a bug.
To work around do the following:-
sudo touch /opt/firefox/extensions/talkback@mozilla.org/chrome.manifest
Installing :
#>First, back up your bookmarks and settings:
cd ~/.mozilla/firefox/*.default
mkdir ~/Desktop/ffsettings
cp bookmarks.html cert8.db cookies.txt formhistory.dat key3.db signons.txt history.dat mimeTypes.rdf ~/Desktop/ffsettings
#>Download firefox-1.5.tar.gz from mozilla.com, and change to the directory you downloaded it to.
#>Install it to /opt/firefox:
sudo cp firefox-1.5.tar.gz /opt/
cd /opt
sudo tar xzvf firefox-1.5.tar.gz
sudo rm firefox-1.5.tar.gz
#>Link to your plugins (and remove totem-mozilla as it doesn't seem to work with Firefox 1.5):
cd /opt/firefox/plugins/
sudo ln -s /usr/lib/mozilla-firefox/plugins/* .
sudo rm libtotem_mozilla.*
#>Change to your home directory, and rename your old profile, leaving it as a backup (using the existing profile may cause problems with Firefox 1.5):
cd
mv .mozilla .mozilla.fc3
#>To ensure it is used as the default version, modify the symbolic link in /usr/bin:
mv /usr/bin/firefox /usr/bin/firefox.bak
sudo ln -s /opt/firefox/firefox /usr/bin/firefox
Restoring should only be done after running firefox at least once and fully closing it.
#>Restore your old data:
cd ~/Desktop/ffsettings
mv * ~/.mozilla/firefox/*.default
#>Restore your Searchplugins:
sudo cp -i --reply=no /usr/lib/firefox[-VER]/searchplugins/* /opt/firefox/searchplugins/
sudo cp -i --reply=no ~/.mozilla/firefox/*.default/search/* /opt/firefox/searchplugins/
#>If you want to keep the original fc3 icon for firefox, enter this command:
sudo cp /usr/share/pixmaps/firefox.png /opt/firefox/chrome/icons/default/default.png
#>To ensure that other programs use version 1.5 of firefox and not the old 1.07 version, go to Preferences -> More Preferences -> Preferred Applications in the System menu. For the "Web Browser" tab, choose "Custom" and then enter the command:
firefox %s
Restoring Extensions and Themes
this should only be done after running firefox at least once and fully closing it.
#> Backup the new profile (just in case):
cd ~/.mozilla/firefox
mkdir ff1.5
mv profiles.ini *.default ff1.5/
#> Restore your previous profile:
cp ~/.mozilla.fc3//firefox/profiles.ini .
cp -r ~/.mozilla.fc3//firefox/*.default .
Updating
To get firefox's own update/autoupdate to work at all, you have three choices (read them all and choose one):
#> Change the /opt/firefox directory to have 'write' permissions & ownership set for the user instead of the root. To change ownership, after installation type:
sudo chown -R username:username /opt/firefox
This is the only way to get update notification working, but doing this has security implications in a multi-user environment, and is not recommended: a virus or malicious program running as a user may now replace or corrupt the files in /opt/firefox, which would affect other users of the computer.
#> An alternative to the above method is to run firefox with sudo to get the updates. That is, when there is an update available, you would run sudo firefox -safe-mode (the safe-mode is an extra layer of protection since it will not load any extensions while running as sudo), install the update (Help -> Check for Updates...), close firefox, and then restart firefox as a normal user. You should NOT browse other websites while you are running firefox with sudo. (It is not known whether this method is any safer/more secure than the first method).
#> A third option, is to use method 1, but only for updates: Keep the firefox folder owned by root and use it normally until you need an update, then give your user ownership: sudo chown -R username:username /opt/firefox. Start firefox normally and update (Help -> Check for updates...). Once the update is completed, you should restore ownership to root: sudo chown -R root:root /opt/firefox. Again, do NOT browse other sites while firefox has these elevated permissions. This is probably the best option although it is also the most cumbersome.
Removing
#> Restore the symbolic link:
sudo rm /usr/bin/firefox
mv /usr/bin/firefox.bak /usr/bin/firefox
#> Restore your old profile:
cd
mv .mozilla .mozilla-1.5
mv .mozilla.fc3 .mozilla
#> (optional) Delete the firefox directory
sudo rm -r /opt/firefox
Monday, January 02, 2006
Session closing problem on browser close
But lets say the user logs in and before loggin out closes browser and leaves. Somebody else comes in and tries to go directly to the restricted page and gets in with the first user logged in. For this you can set the session.cookie_lifetime to '0' which keeps the session alive till browser is closed.
But again this has a problem. The session gets terminated on browser close only if the browser is non-tabbed like IE. The problem exists with tabbed browsers like firefox. If you wish to allow 2 logins at the same time in two different tabs in same window you cant. I found a more severe problem with firefox regarding sessions. Lets say you have multiple firefox windows opened. You login using 1 window. Close that window (not just tab) without loggin out, and try accessing the restricted page using a new or a already existing window and you are in. Isnt this something unexpected. Thats because firefox doesnt terminate sessions till firefox as a whole application is closed and not just the window is closed.
So be carefull when you use such browsers on a public access machine...
Sunday, January 01, 2006
Install PHP5 to be run in parallel with PHP4 in same apache web server instance.
I use Apache 2.0.52 on Fedora core 3. So cant guarantee that this would be helpful to you.
I have installed PHP4 as module and PHP5 as cgi.
Create a cgi-sys folder in /usr/local.
Save the following script as a sh file and run it as root.
Dont forget to check the version of PHP5 you wish to install , the location of PHP currently installed and the location of conf directory for apache.
#!/bin/sh
VERSION=5.1.1
cd /usr/src
wget -O php.tbz2 "http://us3.php.net/get/php-${VERSION}.tar.bz2/from/this/mirror"
tar -xjvf php.tbz2
rm -f php.tbz2
cd php-${VERSION}
PHP='/usr/bin/php'
CFG=`$PHP -i | grep configure | sed "s/'//g" | sed "s/\.\/configure \(.*\)--with-apxs.*apxs \(.*\)/\1 \2/"`
CFGLINE="${CFG##* => } --prefix=/usr/local/php5 --exec-prefix=/usr/local/php5 --enable-force-cgi-redirect --enable-discard-path"
./configure $CFGLINE
HTTPD_CONF_DIR="/etc/httpd/conf"
make
make install
if [ -f /usr/local/php5/bin/php ]
then
# cp -f php.ini-recommended /usr/local/php5/lib/php.ini
cp /usr/local/php5/bin/php /usr/local/cgi-sys/php5
chown root:wheel /usr/local/cgi-sys/php5
echo "ScriptAlias /cgi-sys \"/usr/local/cgi-sys/php5\"" > $HTTPD_CONF_DIR/php5.conf
echo "Action application/x-httpd-php5 \"/cgi-sys/php5\"" > $HTTPD_CONF_DIR/php5.conf
echo "AddType application/x-httpd-php5 .php5" >> $HTTPD_CONF_DIR/php5.conf
TEST=`grep php5.conf $HTTPD_CONF_DIR/httpd.conf`
if [ "$TEST" = "" ]
then
echo "Include ${HTTPD_CONF_DIR}/php5.conf" >> $HTTPD_CONF_DIR/httpd.conf
/etc/init.d/httpd restart
fi
else
echo "There was an error..."
fi
Why Your New External Drive is Breaking Your macOS Builds
Picture this: you're running dangerously low on disk space, so you invest in a brand new external drive. Time to migrate your developmen...
-
VMware Fusion provides a nice functionality of sharing folder from host (Mac OSX) to guest (Ubuntu). But then, it seems they are more focus...
-
Recently, while investigating a production issue, I needed to deploy the production Docker image locally for debugging purposes. However, I ...
-
Picture this: you're running dangerously low on disk space, so you invest in a brand new external drive. Time to migrate your developmen...