Posts

Showing posts from October, 2013

PHP usage tips

1.  Instance usage  Array overwritten after a loop Error code: $att = new Attachment(); for ($i=2; $i<=$parts;$i++){ $att->attachmentHeader = imap_bodystruct($imap, $msgno, $i); $att->attachmentContent = imap_fetchbody($imap, $msgno, $i); $attachments[$i-2] = $att;  } return $attachments; All the objects in the $attachments actually refer to one instance, and this instance object is overwritten by the last $att value. That is because the instance is defined outside the for loop, and every time when the $att is updated, and the $att is updated.  Correct code: for ($i=2; $i<=$parts;$i++){ $att = new Attachment(); $att->attachmentHeader = imap_bodystruct($imap, $msgno, $i); $att->attachmentContent = imap_fetchbody($imap, $msgno, $i); $attachments[$i-2] = $att;  } return $attachments; 2. Be careful of "space" When you define a string and set the value of the string, it is most possible that you will typo a "space" there, t...

email notification setting in ubuntu using postfix

Usage  example:  mail -s 'Error Report' username @example .com < /tmp/message .txt First, on a system have no mail cmd. "mailutils" needs to be installed. sudo apt-get install mailutils I use the postfic-mailx solution.  Install process: sudo apt-get install postfix After the installation is started, some windows will pop up and you need to select options as below: 1. Internet Site 2. Modify the server name when sending an email. You can of course use the default value. Configuration process: sudo dpkg-reconfigure postfix then need to select options as below for the configuration:  Internet Site mail .example.com change the path if needed mail .example.com , localhost.localdomain, localhost No 127.0.0.0/8  [::ffff:127.0.0.0]/104 [::1]/128  192.168.0.0/24 0 + all detail guideline here: https://help.ubuntu.com/11.10/ serverguide/postfix.html And if postfix is already installed by other...

log4php Failed connecting to mysql cluster database & could not find driver

My log4php gets this error in a new server environment. PHP Warning: log4php: [LoggerAppenderPDO:default]: Failed connecting to database. Closing appender. Error: could not find driver in ../log4php/LoggerAppender.php on line 283 I have the same settings for log4php (1. config.xml file 2.same log4php version) as my local development, which works perfectly. I tried simply log to a file in the new server, it works, which means the log4php lib has no problem. And I can even log to the database in the new server from my local script using local log4php lib, which means my server can recognize log4php logging. Reasons: After some searches and tests(script using PDO, not mysqli to connect to the database, good reference  here  and wiki ) , I confirm the problem is caused by lacking of pdo_mysql related driver. As log4php uses PDO extensions in PHP to  log to mysql database. Then PDO extension is needed. As PDO is defaultly included from PHP5.1, and our mysql-cluster ...

Regular expression live website and PHP regex trick with backslash

Regular expression is really help to process data. But a tiny typo can hardly be aware and that is why a "live" regex is really helpful for newbie as me when learning it. Below is a list of live regex for different coding language. PHP,   phpliveregex . An important note, if you use "\\_" in php to get "\_", which means escape the first "\", you actually need "\\\\_" in the regex in PHP. Ruby,  rubular

PHPUnit introduction and possible warnings/errors

1.  Beginner guidebook I am using Ubuntu 12.04, so below may only available for 12.04 and can have issues when using different unix system. 2.  Installation Cmd below will install the latest PHPUnit. And you need install "pear" first. >sudo pear install -- alldeps -- force phpunit / phpunit 3. Modify the php.ini First, find the php path: > pear config-show | grep php_dir                                   PEAR directory                 php_dir          /usr/share/php Then find  the php.ini file >locate php.ini    And change the include_path in php.ini to the value of php_dir: include_path = ".:/usr/share/php"                                 4. The output of the PHPUnit result >phpunit path/to/file/ClassName...

Security warning in MYSQL 5.6

Changes from MySQL 5.6.5: Security Fix: MySQL client programs now issue a warning if a password is given on the command line that this can be insecure. So, if you use a plain-text password/argument in the script like below: shell>mysql --user=${myuser} --password=${mypasswd} --port=${myport} --host=${myhost} ${mydb} Then you will get this warning: Warning: Using a password on the command line interface can be insecure. Solution: Suggestions from MYSQL bug forum . A better solution is to use mysql_config_editor which MYSQL officially suggested to add the called "mysqlpath" object which generated crypted credential for the mysql database. It is in the bin folder in your installed MYSQL5.6 folder. 1. To find the "mysql_config_editor" cmd, you can use: shell> which mysql_config_editor My case, it is in the path:  /usr/local/mysql-advanced-5.6.11-linux-glibc2.5-x86_64/bin/mysql_config_editor Note: if the "which" shows no result, it means...