<input ... ></input><input ... >
register_globals = Off
allow_url_fopen = Off in php.ini
open_basedir = /var/www/htdocs/files
safe_mode = Off Enable Acess to Group safe_mode_gid = On
Allow binary execution from directory safe_mode_exec_dir = /var/www/binaries Allow Access to environment variables, say starting with PHp safe_mode_allowed_env_vars = PHP_ Limit Resourcesmax_execution_time = 30 ; Max script execution time max_input_time = 60 ; Max time spent parsing input memory_limit = 16M ; Max memory used by one script upload_max_filesize = 2M ; Max upload file size post_max_size = 8M ; Max post size
Limit access to certian file name patterns(prevent .inc & .sql files) In Apache conf
<FilesMatch "\.(inc|.*sql|.*~)$"> Order allow,deny Deny from all </FilesMatch> Error Message & logging display_errors = Off
log_errors = On
Hide php extension expose_php = Off
- Debugging suddenly stops working, no wath points, console.log starts giving errors: Disable & enable console that solves this
select * from sample limit 0,10
select * from sample limit 10,20
instead of this, we can write
SELECT * FROM sample LIMIT 0,11
if this returns 11 rows, You know next set of rows exist so you can enable next link
InnoDB
MYISAM
- Good for low write, high read applications, as table level lock happens for write
- Key_buffer_size should be ¼ th of total RAM
- .frm(definition structure of table), .MYI(index), .MYD(data) files for all tables in mysql directory
- Supports INSERT_DELAYED, LOW_PRIORITY, HIGH_PRIORITY – can be used in statements to prioritize statements
- Supports fulltext search
- Supports MERGE
- Disabling of non unique indexes while loading data will help in fast insertion
- Supports storage formats fixed, dynamic-row, compressed
MERGE
- provides logical entity that exceeds MYISAM table size
- logically query on merge acts as query on all inner myisam tables
- supports select,insert,update,delete. Should specify in create table that inserted item should go to first or last table.
- MERGE creates .MRG text file
- CREATE TABLE table_name (id INT ….) ENGINE=MERGE UNION(table1, table2)
- Increases number file descriptors opened as it opens all underlying tables.
- It’s slower as it opens multiple indexes.
INNODB
- Supports transactions.
- Supports foreign key and referential integrity
- Innodb_buffer_pool_size should be 80% of total memory
- Supports auto recovery after crash.
- Shares same storage space for all tables(unless innodb files per table set), not constrained by file size limitations of OS.
- Manages query contention by multi versioning & row level locking
- innodb_flush_log_at_trx_commit w0/1/2 to set flushing on every commit/every 1 sec/only db flush on every commit
- show engine innodb status;
MEMORY
- Data and indexes are stored in memory, results in faster performance
- Uses table level locking
- Data don’t survive after restart.
- Don’t support TEXT & BLOB
FEDERATED
- Allows to use tables from other servers & make them available to clients as if tables were its own.
- COMMENT=mysql://user_name[:password]@host_name[:port]/db_name/table_name should be added to make federated table.
BLACKHOLE
- Engine discards all the data stored in, but logs in bin_log if enabled.
- USES; trigger for insertion
- Uses; verification of syntax
- Uses; to measure performance of logging;
- Uses; measure application performance not related to storage.
Normalization
1NF: Each column of table has to be atomic, no set values with in column
2NF: non key columns must depend on entire primary key.
3NF: Non key field should not depend on another non key field
4NF: A record should not contain two or more independent multi valued facts about enity.
SQL QUERY Syntax
CREATE TABLE
Create table table_name ( column definition ) ENGINE=INNODB;
Create table table_name select …. è creates & populates table with contents returned from select
Create table table_name like table è creates empty table
CREATE TEMPORARY TABLE mail SELECT * FROM mail è creates temp table ALTER TABLE
ADD colmn_name INT NOT NULL
MODIFY id BIGINT
CHANGE old_clmn_name new_clmn_name
t1 RENAME TO t2
RENAME TABLE t1 to t2
DROP TABLE
Drop table if exists no_table;
INDEX
primary kay and unique fields create indexes automatically
ALTER TABLE ADD INDEX index_name(id) è creates named index
Create index index_name USING btree on table_name (id) è To use btree algorithm for indexing
ALTER TABLE table_name DROP PRIMARY KEY
DROP INDEX ‘primary’ ON t
SHOW INDEX FROM table_name;
USER VARIABLES
Set @var1=’
PREPARED STATEMENTS
Prepare stmt_name from ‘Select …. Where id =?’;
Execute stmt_name using @variable;
Deallocate stmt_name;
PROCEDURE
Create procedure test_proced()
BEGIN … END
TRIGGER
Create trigger trigger_name Before/after Insert/update/delete On table_name For each row Trigger_stmt
FULL TEXT
SELECT COUNT(*) from kjv WHERE MATCH(vtext) AGAINST('Mizraim');REGEXP
SELECT name FROM metal WHERE name REGEXP '^[aeiou]|er$';
VARIABLES
Set @var_name = select name;
ANY/ALL
Select ….. where pop > ALL ( select …)
Exists, any , all , any <>
SHOW
SHOW TABLE STATUS LIKE 'mail'\G
SHOW CREATE TABLE mail\G
QUERY CACHE
Query_cache_type=2 (DEMAND)lets u choose SQL_CACHE in the query
Query_cache_size
Server side query prepared statements cannot use query cache
Select status like ‘Qcache%’ == query cache status hits/misses/free memory
Optimizing query
Check slow query log
log-queries-not-using-indexes –enable
- USE INDEX(P1), to force to use index
- Analyze table ..
- Show warnings
For tables that are being accessed frequently
Create separate key cache “set global city _cache.key_buffer_size=1024; creates city_cache with 1KB size
Cache index world.city in city_cache
Load index into cache worl.cache
- slect … PROCEDURE ANALYZE() == will show you optimal values to be used for columns
VIEW
Creat view as
Restrictions: - No temporary views, no triggers,
select statement cannot have – subqueries in where, cannot reference variables stored procedure,
WITH CHECK OPTION – causes condition in the where clause of view definition to be checked when updates attempted.
Information_schema.views will have information about the view
IMPORT EXPORT
Load data infile file_name into table table_name;
Select * into outfile file_name from table_name;
Mysqlimport –h host –u user db_name input_file
Mysqlimport db_name file_name
SETTINGS (OPTIMIZATION)
Thread_cache_size nos of extra connections to be kept
Sort_buffer = should be high if lot sorting is used
Table_locks_waited/Table_locks_immediate = table contention
Show status like ‘Created_tmp%’
Table maintenance
- check table
- repair table
- analyze table
- mysqlcheck
- myisamcheck
Backup
- Binary backup: mysqlhotcopy, InnoDBhotcopy
- Text Backup: “select … into outfile”, mysqldump
Binary backup
Lock the table and Cp files .MYI, .MYD and .frm from mysql directory.
Mysql hot copy
COMMANDS/TOOLS
Mysqldumpslow
Mysqlbinlog
myisampack
Mysql
Mysqldump
Mysqlimport
Mysqladmin
Mysqlcheck
Myisamchk
> Use index Keys in query in the query,
Surprisingly using secondary keys (non primary) shows better performance than using primary keys.
Using Primary Key
mysql> select SQL_NO_CACHE count(*) from ball_details use index(PRIMARY);
+----------+
| count(*) |
+----------+
| 156228 |
+----------+
1 row in set (0.14 sec)
Using non primary key
mysql> select SQL_NO_CACHE count(*) from ball_details use index(index_ball_id);
+----------+
| count(*) |
+----------+
| 156228 |
+----------+
1 row in set (0.09 sec)
But mysql is smart enough to use non primary key, explain tells u this
mysql> explain select count(*) from ball_details;
+----+-------------+--------------+-----
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------------+-----
| 1 | SIMPLE | ball_details | index | NULL | index_ball_id | 4 | NULL | 152377 | Using index |
+----+-------------+--------------+-----
1 row in set (0.00 sec)
> using show table status
If total count is not critical and 1-2% of difference in total count is fine then, show table status can be used.
e.g: show table status like 'ball_details';
1 row in set (0.02 sec)
Links related to count(*) performance.
http://www.mysqlperformanceblog.com/2006/1
You vcan find very good example at http://www.php.net/manual/en/language.oo
Other similar implementation s,
implement several interfaces an then compose a common
classes that implements said interfaces. this is the workaround
for single inheritance languages. here is a trivial example,
interface CommonStuff {
function commonFunction($a, $b);
function moreCommonFunction($x, $y, $z);
}
interface OftenUsed {
function imSpecial($c, $d);
function imMoreSpecial($u, $v, $w);
}
now you might have standard or common implementations
of these, sometimes referred to as mixins (taken from ruby,
i believe [<-- here i go again greg ;)])
class CommonStuffImpl implements CommonStuff {
function commonFunction($a, $b) {
return $a + $b;
}
function moreCommonFunction($x, $y, $z) {
return $x + $y + $z;
}
}
class OftenUsedImpl implements OftenUsed {
function imSpecial($c, $d) {
return $c - $d;
}
function imMoreSpecial($u, $v, $w) {
return $u - $v - $w;
}
}
and now finally for the multiple inheritance workaround;
suppose you have a class that needs to be both
CommonStuff and OftenUsed; you simply implement
both the interfaces, then delegate to the mixins, and
viola! multiple inheritance the single inheritance way ;)
class MultiInherit implements CommonStuff, OftenUsed {
private $commonStuffImpl = null;
private $oftenUsedImpl = null;
public function __construct() {
$commonStuffImpl = new CommonStuffImpl();
$oftenUsedImpl = new OftenUsedImpl();
}
/// now make sure to implement the interfaces and delegate
function commonFunction($a, $b) {
return $this->commonStuffImpl->commonFunction($a,
}
function moreCommonFunction($x, $y, $z) {
return $this->commonStuffImpl->moreCommonFuncti
}
function imSpecial($c, $d) {
return $this->oftenUsedImpl->imSpecial($c, $d);
}
function imMoreSpecial($u, $v, $w) {
return $this->oftenUsedImpl->imMoreSpecial($u, $v, $w);
}
}
Reference : http://www.nabble.com/Multiple-Inheritan
watch runs commands periodically,outputs in full screen
e.g watch -n 2 ls -l ==> runs 'ls -l' every 2 seconds
watch -d ls -l ==> highlights diff in out puts
pstree shows tree of processes
e.g pstree
init-+- getty
|- getty
|- getty
fuser Identify the process used by file or socket
e.g fuser /home/notroot ==> lists process that r using /home/notroot
fuser -km /home/notroot ==> kills all the processes that r using /home/notroot
mysqldump --no-data --all-databases -u root -pPASSWD >>cricket_schema.sql
On destination machine
mysql -u root
mysql> source /home/sudhirp/cricket_schema.sql;
- Location:bangalore, india
Linux:
$ sudo netstat -lnptu|grep apache
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11151/yapache
tcp 0 0 0.0.0.0:4080 0.0.0.0:* LISTEN 11151/yapache
BSD:
$ sockstat -4l|grep apache
nobody yapache 21369 19 tcp4 *:80 *:*
root yapache 21367 19 tcp4 *:80 *:*
root yapache 6429 20 tcp4 *:1556 *:*
$ grep ftp /etc/services
ftp-data 20/tcp
ftp-data 20/udp
$ sudo netstat -lnptu|grep apache
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11151/yapache
tcp 0 0 0.0.0.0:4080 0.0.0.0:* LISTEN 11151/yapache
for more details read this article, http://blogs.techrepublic.com.com/securi
- Location:bangalore
By default Curl header is set no-cache so every time u hit a URL with proxy(squid) it’s a cache miss. Unset pragma header while curling to avoid this problem.
From command mode
curl -H "Pragma:" -x 'localhost:3128' URL
From PHP code
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array("Pragma: "));
http://in.php.net/curl_setopt
http://curl.haxx.se/docs/manpage.html#-H-
http://curl.haxx.se/mail/archive-2002-07/0
but real problem lies at backend how algorithms and data structures used.
Below are the few ways that could be used
1> Modifying simple trie like structure. every charecters on the path will have remaining charecters in the word. go through below link for more info
http://rmandvikar.blogspot.com/2008/1
But this can only be used for matches.
2>usig suffix trees
http://www.allisons.org/ll/AlgDS/Tree/S
but ther is lot more to it, like how to rank or prioritize strings. I could not find implementations of these.anybody have any links or suggestions? would be really helpful
First of all you should have at least 6moths-1 Year of coding experience in PHP unless ur really geeky kind of a person. Exam isn't very hard but u need to have good preparation. It had many question related other web technologies like XML, security and not just PHP. I would rank exam difficulty as medium. Some thing very irritating is, lot of questions about function names and whats more some of these function names have to be entered, u got it right no multiple choice. Surprisingly lot of questions about file uploads, i didnt do well in those.
Now coming to preparation
- Must read book "zend php 5 certification study guide" Good thing about this book is it restricts ur reading to topics which are most likely to appear in the exam. Read and re-read this book. Buy it above given link or just search around u will get free pdf download.
- Other helpful books "php cook book" by oreilly, "php 5 power programming" by oreilly, "PHP 5 Objects, Patterns, and Practice" By Matt Zandstra This is really good book if you want to know about OOP & design patterns but not needed for exam sake. "Pro PHP XML and Web Services" by Robert Richards good for advanced knowldge of xml & web services but over kill for exam.
- Online blogs/links http://www.devshed.com/c/a/Zend/Taking-t
he-Zend-Certified-PHP-Engineer-Exam-My-S tory/,www.zend.com/en/services/certification/p hp-5-certification/, just search around net you would get many. - Zend yellow pages Lists who cleared this exam recently, u may leave private message. For india this is link the Lihttp://www.zend.com/store/education/ce
rtification/yellow-pages.php#list-cid=10 2&firstname=&lastname=&orderby=name&sid=X X&company=&photo_first=&certtype=PHP5&Cl ientCandidateID= - Practice test The Zend PHP Certification Practice Test Book , search around u may get free pdf download.
- Online test I bought 5 online test pack, better attend few online test before going for exam. most of the questions were repeated in 3rd & 4th online tests so not sure if it makes any sense to go for 10 online test pack.
- How to take exam Contacted zend sales people through https://www.zend.com/en/contact, got $25 rebate and paid money online. Take print out of the voucher & dont forget note down the voucher number before going to test center. May be u can directly go to test center and pay money but not sure just check out with test center.
- Test Centers in india, I had to wait for more than 1and half hours at test center. https://vss.pearsonvue.com/VSSReports/Ac
tiveIndiaTestingCenters.cfm.
UPDATE:
Recently found new blog regarding preparation http://saidur.wordpress.com/2008/12/05/h
To find and delete files older than 3 days
find /home/y/var/dbdist/feedfactory/ -mtime +3 -exec sudo rm {} \;
Get CPU Details(like type cpu, nos of cores etc)
FreeBSD
sysctl -a | egrep -i 'hw.machine|hw.model|hw.ncpu'LINUX
cat /proc/cpuinfo
- top : Will show you the current memory and cpu utilization
- ps -aux : Shows the %mem,%cpu etc consumed by the process, use it with process id to get details of that process only
- vmstat 2 : shows virtual memory statistics for every 2 seconds.
- cat /proc/<pid>/status : Shows you more detailed information about the process
- ipcs -u : Shows shared memory status in segments, semaphores and queues
- systat vmstat 1 : Shows Detailed virtual memory usage(Only in Free BSD).
Move all files from directory $1 to directory $2, and use the xargs -t option to echo each move as it happens:
ls $1 | xargs -I {} -t mv $1/{} $2/{}
The following example finds the unique owners of all the files in the /bin directory:
# all on one line
find /bin -type f -follow | xargs ls -al | awk ' NF==9 { print $3 } '|sort -u
reference http://www.unixreview.com/documents/s=82
Compress folder Test/ to Test.tar.gz
tar czfv Test.tar.gz Test/
czfv = ‘Compress Zip File Verbose’
If you want bzip files, use ‘j’ instead of ‘z’.
Uncompress Test.tar.gz to folder Test/
tar -xzf Test.tar.gz
x = ‘eXtract’
Again, if you want bzip files, use ‘j’ instead of ‘z’.
http://en.wikipedia.org/wiki/Tar_(file_f
Reference
http://txt.binnyva.com/2007/02/command-t
:%s/<char>/^M/g
NOTE: ^M should typed by holding control key first type^ then M
Vim doesn't format xml structures. Its very difficult to read xml in vim & its very kludgy too. Here is tip to solve this by xmllint, use this command
xmllint --format filename | vi -
by default xmllint should have been installed on linux boxes.
- Mood:
excited
