Recent Updates RSS Toggle Comment Threads | Keyboard Shortcuts

  • Dipak Karki 10:03 am on May 8, 2012 Permalink | Reply  

    What is umask ? 

    When user create a file or directory under Linux or UNIX, she create it with a default set of permissions. In most case the system defaults may be open or relaxed for file sharing purpose. For example, if a text file has 666 permissions, it grants read and write permission to everyone. Similarly a directory with 777 permissions, grants read, write, and execute permission to everyone. When a directory is created in PHP using mkdir and setting the permission to 0755 or to any other writable value, and if it still denys permission to add files inside that directory then we need to change the umask default value . For example

    The umask() function in PHP changes the file permissions for files.

    This function sets PHP’s umask to mask & 0777 and returns the old umask. However, if you call umask() without any arguments, it returns the current umask.

     

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 10:05 am on April 27, 2012 Permalink | Reply  

    How to run a PHP process or task in the background ? 

    You can run the command in the background by adding a & at the end of it as:

    exec(‘command &’);

    But doing this alone will hang your script because:

    If a program is started with exec function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

    So you can redirect the stdout of the command to a file, if you want to see it later or to /dev/null if you want to discard it as:

    exec(‘run_baby_run > /dev/null &’);

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 8:53 am on April 27, 2012 Permalink | Reply  

    What is Gearman ? 

    Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. It allows you to do work in parallel, to load balance processing, and to call functions between languages. It can be used in a variety of applications, from high-availability web sites to the transport of database replication events. In other words, it is the nervous system for how distributed processing communicates. A few strong points about Gearman:

    A Gearman powered application consists of three parts: a client, a worker, and a job server. The client is responsible for creating a job to be run and sending it to a job server. The job server will find a suitable worker that can run the job and forwards the job on. The worker performs the work requested by the client and sends a response to the client through the job server. Gearman provides client and worker APIs that your applications call to talk with the Gearman job server (also known as gearmand) so you don’t need to deal with networking or mapping of jobs. Internally, the gearman client and worker APIs communicate with the job server using TCP sockets. To explain how Gearman works in more detail, lets look at a simple application that will reverse the order of characters in a string. The example is given in PHP, although other APIs will look quite similar.

    We start off by writing a client application that is responsible for sending off the job and waiting for the result so it can print it out. It does this by using the Gearman client API to send some data associated with a function name, in this case the function “reverse”. The code for this is (with error handling omitted for brevity):

    For more details please visit http://gearman.org/index.php

    Source: gearman.org

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 11:41 am on April 23, 2012 Permalink | Reply  

    Finding combinations of each items in an array 

    There are times, where you want to get the combination of each items in an array . Function presented below demonstrates how each items can be combined with others . This function can be used to test several alternatives that might encounter during a live deployment of an application by passing the resultant combination as a post or get data.

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 5:48 am on April 23, 2012 Permalink | Reply
    Tags: Utilities   

    Compile or run your Web application online 

    CodeRun is an online web application that provides you with the provision of online compilation of ASP.net, javascript and PHP scripts. IT appears like an online visual studio .net editor with limited features. This application is useful to those, who would like to understand the code related to c# or PHP without having to install the relevant softwares in the local machine. If you are a PHP developer and would like to convert the logic of ASPX into PHP then these types of online editor comes into useful.

    You can use this online compiler at http://www.coderun.com/ide/

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 5:41 pm on March 23, 2012 Permalink | Reply
    Tags: md5   

    MD5 Decrypter 

    There are some situations, where you have to hack the md5 passwords. the url http://md5.noisette.ch/ or http://md5.darkbyte.ru contains API that can help you to decrypt md5 password.

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
    • Dipak Karki 2:39 pm on March 28, 2012 Permalink | Reply

      Thanks to Jeremy Gomez, for providing this information

  • Dipak Karki 4:48 pm on March 16, 2012 Permalink | Reply
    Tags: , security   

    How to secure PHP production server 

    The Apache/PHP/MySQL stack is immensely popular for web application development. Its components are powerful, versatile and Free. Unfortunately however, PHP comes with a default configuration that is not suitable for production mode, and may cause developers to use insecure techniques during the development phase. Inside is a check list of settings that are intended to harden the default PHP installation.

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 12:18 pm on March 16, 2012 Permalink | Reply
    Tags: ,   

    Get DPI value of an image using PHP 

    DPI is an acronym for Dot per inch. This information is required to decide the quality of images specially for printing press. Inorder to extract these information you need to read the information of an image. Code below is a simple example of reading the information of an image and extracting the DPI information. This sometime might not work for images that has different encoding.

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 5:52 am on March 16, 2012 Permalink | Reply
    Tags: mysql   

    What is the difference between mysql and mysqli 

    mysqli and mysql refers to the PHP drivers that can communicate with the mysql database server. mysqli is an improved or enhanced version of mysql. It means mysql is the old database driver. Mysqli takes advantage of the new features included in Mysql5, such as

    • Object oriented interface
    • Support for prepared statements
    • Support for multiple statements
    • Support for transactions
    • Enhanced debugging capablities
    • Embeded server support
    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 4:58 pm on March 15, 2012 Permalink | Reply
    Tags: ,   

    Object oriented PHP for beginners 

    I came across a good tutorial on object oriented PHP . Please check it out here.  This tutorial will help beginners to understand the details of object oriented PHP ,at the same time it would act as a reference for a object oriented PHP exprts.

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 10:04 am on February 28, 2012 Permalink | Reply  

    Classes in javascript 

    JavaScript is a very flexible object-oriented language when it comes to syntax. In this article you can find three ways of defining and instantiating an object. Even if you have already picked your favorite way of doing it, it helps to know some alternatives in order to read other people’s code.

    It’s important to note that there are no classes in JavaScript. Functions can be used to somewhat simulate classes, but in general JavaScript is a class-less language. Everything is an object. And when it comes to inheritance, objects inherit from objects, not classes from classes as in the “class”-ical languages.

    To define classes in javascript as a object oriented pattern, please visit http://www.phpied.com/3-ways-to-define-a-javascript-class/

     

     

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 8:56 am on January 1, 2012 Permalink | Reply  

    How to create custom views helper function in Zend Framework? 

    In order to create custom helpers function for views, follow the following steps

    1. Create a file with the name of the helper function at application/views/helpers/. for example: application/views/helpers/translate.php
    2. Create a class with <Prefix>_View_Helper_<Name of the helper function>: For example: Default_View_Helper_Translate
    3. In the class created in step 2, define a function with the name of the helper function . For example function translate()
    4. Register the helper fucnction path in application/configs/application.ini as in the example below:
      resources.view.helperPath.Default_View_Helper = APPLICATION_PATH “/views/helpers”
    5. Call the helper function in your layout or views like: $this->translate();
    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 5:47 am on January 1, 2012 Permalink | Reply  

    Zend view helper function 

    The View Helper contains a set of concrete placeholder methods. The methods allow you to set the doctype, set the page title, add metadata elements, add link elements, and insert inline scripts in your view with a single line of PHP

    • doctype(String)
      Creates the <doctype> element for the markup. Acceptable values: XHTML11, XHTML1_STRICT, XHTML1_TRANSITIONAL, XHTML1_FRAMESET, XHTML_BASIC1, HTML4_STRICT, HTML4_LOOSE, HTML4_FRAMESET, HTML5
    • headLink()
      Creates the <link> element within your markup. Available methods: appendStylesheet($href, $media, $conditionalStyleSheet, $extras) setStylesheet(($href, $media, $conditionalStyleSheet, $extras) Example: $this->headLink()->appendStylesheet();
    • headMeta()
      Creates the <meta> element within your markup. Available methods: appendName($keyvalue, $content, $conditionalName) setName($key, $content, $conditionalName) setHttpEquiv($key, $content, $modifiers)
      Example:
      $this->headMeta()-.>setHttpEquiv();
    • headScript()
      Creates the <script> element within your markup. Available methods: appendFile($src, $type, $attributes) setFile($src, $type, $attributes)
      appendScript($script, $type, $attributes) setScript($script, $type, $attributes)
    • headStyle()
      Creates the <style> element within your markup. Available methods: appendStyle($content, $attributes) setStyle($content, $attributes)
      Example:
      $this->headStyle()->setStyle();
    • headTitle()
      Creates the <title> element within your markup.
    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 10:08 am on November 13, 2011 Permalink | Reply
    Tags: CURL, , , PHP and curl, proxy   

    Using proxies with curl in php 

    In PHP there are two popular methods to get contents from a url.

    1. file_get_contents
    2. CURL

    Among the 2 methods the best recommended method is CURL. CURL can request data from a secured connection, password protected pages or modify the header request,which are the chief advantages over file_get_contents. CURL is also faster then file_get_contents method.

    Besides the above benefits of CURL over file_get_contents, CURL can also use different types of proxies and proxy IP. If you would need to make a frequent request of a data from the particular site, there might be chances that they block your IP thinking you as a spam used for attacking the server. So to avoid such service interruption, you can use different proxies .

    Below is a php code snippet, that demonstrate the use of CURL defining the proxy address

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
  • Dipak Karki 1:18 pm on November 9, 2011 Permalink | Reply
    Tags: project management, SVN   

    Using free remote SVN Repositories for your projects. 

    If you are looking for free SVN repositories to add your code for future reference in the remote server, or to sync your project across platforms and developers then xp-dev.com is a perfect site. It offers free and premium service for svn hosting.

    • Print
    • Digg
    • StumbleUpon
    • del.icio.us
    • Facebook
    • Twitter
    • PDF
     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel