<?php
echo PHP_OS;
?>
<?php
echo stristr(PHP_OS, 'WIN') ? 'Its Windows' : 'Others';
?>
predefined constants
<?php
echo PHP_OS;
?>
<?php
echo stristr(PHP_OS, 'WIN') ? 'Its Windows' : 'Others';
?>
<?php
$startRow = 0;
$rowPerPage = 10;
$totalRow = 111;
$runCycle = (int)($totalRow / $rowPerPage);
run_yahoo($startRow, $rowPerPage, $totalRow);
function run_yahoo($startRow, $rowPerPage, $totalRow) {
$runCycle = (int)($totalRow / $rowPerPage);
if (($totalRow % $rowPerPage) != 0) {
$runCycle++;
}
$nextStartRow = NULL;
for ($i = 0; $i < $runCycle; $i++) {
$nextStartRow = $nextStartRow ? $nextStartRow : $startRow;
$nextStartRow = _get_yahoo_data($nextStartRow, $rowPerPage, $totalRow);
}
}
function _get_yahoo_data($startRow, $rowPerPage, $totalRow) {
$nextStartRow = $startRow + $rowPerPage;
echo 'LIMIT ' . $startRow . ', ' . $nextStartRow . '
';
return $nextStartRow;
}
?>
<?php
bool mail ( string $email_address_to, string $subject, string $message_contents [, string $additional_headers [, string $additional_parameters]] );
?>
<?php
mail ( $email_address_to , $subject, $message_contents );
?>
<?php
$email_address_to = "recipient@demo.com";
$subject = "Test email subject";
$message_contents = "Hi! This is the content of the test message.";
$header = "From: sender@demo.com\r\n";
$header .= "Reply-To: sender@demo.com\r\n";
$header .= "Return-Path: sender@demo.com\r\n";
mail($email_address_to,$subject,$message_contents,$header);
?>
<?php
// --- CONFIG PARAMETERS --- //
//
$email_recipient = "recipient@demo.com";
$email_sender = "Sender Name";
$email_return_to = "sender@demo.com";
$email_content_type = "text/html; charset=us-ascii";
$email_client = "PHP/" . phpversion();
//
// ------------------------- //
// --- DEFINE HEADERS --- //
//
$email_header = "From: " . $email_sender . "\r\n";
$email_header .= "Reply-To: " . $email_return_to . "\r\n";
$email_header .= "Return-Path: " . $email_return_to . "\r\n";
$email_header .= "Content-type: " . $email_content_type . "\r\n";
$email_header .= "X-Mailer: " . $email_client . "\r\n";
//
// ---------------------- //
// --- SUBJECT AND CONTENTS --- //
//
$email_subject = "Test email subject";
$email_contents = "<html>";
$email_contents .= "<h2>Test Email</h2>";
$email_contents .= "<br><b>Sender: " . $email_sender;
$email_contents .= "<br><b>Recipient: " . $email_recipient;
$email_contents .= "</html>";
//
// ---------------------------- //
$email_result = mail($email_recipient, $email_subject, $email_contents, $email_header);
if ($email_result) echo "Email has been sent!";
else echo "Email has failed!";
?>
sites/default/settings.php
sites/example.com/settings.php
sites/example.com.site3/settings.php
sites/sub.example.com/settings.php
sites/sub.example.com.site3/settings.php
sites/sub.example.com/settings.php
sites/sub.example.com/themes/custom_theme
sites/sub.example.com/modules/custom_module
$ ln -s sites/example.com sites/www.example.com
$ ls -l sites
-rw-rw-r-- 1 drupal drupal sites/example.com
lrwxrwxrrx 1 drupal drupal sites/www.example.com -> sites/example.com
::1 localhost
127.0.0.1 localhost loghost
202.12.122.129 web020.mydomain.com web020 mx0 # this machine WAN
192.168.100.152 web021.mydomain.com web021 # this machine LAN
domain MyDomain.com
nameserver my actual name server and not my router/gateway, as I am not behind a router, but I was when I configured the server
nameserver my backup name server
//domain: The local domain name.
//search: Search list for hostname lookup. This is normally determined by the domain of the local hostname.
//nameserver: The IP address of a name server the resolver should query. The servers are queried in the order listed with a maximum of three.
<?php
mail($usermail, $subject, $message, "From: $adminmail\nX-Mailer: PHP/", "-odb -f $adminmail");
?>
<?php
$fd = popen("/usr/sbin/sendmail -t","w") or die("Couldn't Open Sendmail");
fputs($fd, "To: recipient@hisdomain.com \n");
fputs($fd, "From: \"Your Name\"\n");
fputs($fd, "Subject: Test message from my web site \n");
fputs($fd, "X-Mailer: PHP3 \n\n");
fputs($fd, "Testing. \n");
pclose($fd);
?>
v=spf1 ip4:202.27.122.192/26 a mx a:web020.mydomain.com a:www.mydomain.com mx:mydomain.com ~all
<?php $target = 'some text'; if(preg_match('/ e # Comments here /x',$target)) { print "Target 1 hit.\n"; } if(preg_match('/ e # /Comments here with slash /x',$target)) { print "Target 1 hit.\n"; } ?>
<?php $examples = array( 'Valid ASCII' => "a", 'Valid 2 Octet Sequence' => "\xc3\xb1", 'Invalid 2 Octet Sequence' => "\xc3\x28", 'Invalid Sequence Identifier' => "\xa0\xa1", 'Valid 3 Octet Sequence' => "\xe2\x82\xa1", 'Invalid 3 Octet Sequence (in 2nd Octet)' => "\xe2\x28\xa1", 'Invalid 3 Octet Sequence (in 3rd Octet)' => "\xe2\x82\x28", 'Valid 4 Octet Sequence' => "\xf0\x90\x8c\xbc", 'Invalid 4 Octet Sequence (in 2nd Octet)' => "\xf0\x28\x8c\xbc", 'Invalid 4 Octet Sequence (in 3rd Octet)' => "\xf0\x90\x28\xbc", 'Invalid 4 Octet Sequence (in 4th Octet)' => "\xf0\x28\x8c\x28", 'Valid 5 Octet Sequence (but not Unicode!)' => "\xf8\xa1\xa1\xa1\xa1", 'Valid 6 Octet Sequence (but not Unicode!)' => "\xfc\xa1\xa1\xa1\xa1\xa1", ); echo "++Invalid UTF-8 in pattern\n"; foreach ( $examples as $name => $str ) { echo "$name\n"; preg_match("/".$str."/u",'Testing'); } echo "++ preg_match() examples\n"; foreach ( $examples as $name => $str ) { preg_match("/\xf8\xa1\xa1\xa1\xa1/u", $str, $ar); echo "$name: "; if ( count($ar) == 0 ) { echo "Matched nothing!\n"; } else { echo "Matched {$ar[0]}\n"; } } echo "++ preg_match_all() examples\n"; foreach ( $examples as $name => $str ) { preg_match_all('/./u', $str, $ar); echo "$name: "; $num_utf8_chars = count($ar[0]); if ( $num_utf8_chars == 0 ) { echo "Matched nothing!\n"; } else { echo "Matched $num_utf8_chars character\n"; } } ?>csaba at alum dot mit dot edu
<?php $lineFirst = "This is a new first line<br>\r\n"; $lineLast = "This is a new last line<br>\r\n"; $page = <<<EOD <html><head> <title>This is a test page</title> </head><body> This is the first line<br> Hi Fred<br> Hi Bill<br> This is the last line<br> </body> </html> EOD; $re = "/<body>.*^(.+)(^.*?^)(.+)(^<\\/body>.*?)/smU"; if (preg_match($re, $page, $aMatch, PREG_OFFSET_CAPTURE)) $newPage = substr($text, 0, $aMatch[1][1]) . $lineFirst . $aMatch[2][0] . $lineLast . $aMatch[4][0]; print $newPage; ?>
<?php function drupal_validate_utf8($text) { if (strlen($text) == 0) { return TRUE; } return (preg_match('/^./us', $text) == 1); } ?>
IPF="ipfw -q add"
ipfw -q -f flush
#loopback
$IPF 10 allow all from any to any via lo0
$IPF 20 deny all from any to 127.0.0.0/8
$IPF 30 deny all from 127.0.0.0/8 to any
$IPF 40 deny tcp from any to any frag
# statefull
$IPF 50 check-state
$IPF 60 allow tcp from any to any established
$IPF 70 allow all from any to any out keep-state
$IPF 80 allow icmp from any to any
# open port ftp (20,21), ssh (22), mail (25)
# http (80), dns (53) etc
$IPF 110 allow tcp from any to any 21 in
$IPF 120 allow tcp from any to any 21 out
$IPF 130 allow tcp from any to any 22 in
$IPF 140 allow tcp from any to any 22 out
$IPF 150 allow tcp from any to any 25 in
$IPF 160 allow tcp from any to any 25 out
$IPF 170 allow udp from any to any 53 in
$IPF 175 allow tcp from any to any 53 in
$IPF 180 allow udp from any to any 53 out
$IPF 185 allow tcp from any to any 53 out
$IPF 200 allow tcp from any to any 80 in
$IPF 210 allow tcp from any to any 80 out
# deny and log everything
$IPF 500 deny log all from any to anySave and close the file.
# Set this to your ip address.
ip="192.168.1.5"
fwcmd="ipfw"
setup_loopback
# Allow anything outbound from this address.
${fwcmd} add allow all from ${ip} to any out
# Deny anything outbound from other addresses.
${fwcmd} add deny log all from any to any out
# Allow TCP through if setup succeeded.
${fwcmd} add allow tcp from any to any established
# Allow IP fragments to pass through.
${fwcmd} add allow all from any to any frag
# Allow all IPv6 packets through - they are handled by the separate
# ipv6 firewall rules in rc.firewall6.
${fwcmd} add allow ipv6 from any to any
# Allow inbound ftp, ssh, email, tcp-dns, http, https, imap, imaps,
# pop3, pop3s.
${fwcmd} add allow tcp from any to ${ip} 21 setup
${fwcmd} add allow tcp from any to ${ip} 22 setup
${fwcmd} add allow tcp from any to ${ip} 222 setup
${fwcmd} add allow tcp from any to ${ip} 25 setup
${fwcmd} add allow tcp from any to ${ip} 53 setup
${fwcmd} add allow tcp from any to ${ip} 80 setup
${fwcmd} add allow tcp from any to ${ip} 443 setup
${fwcmd} add allow tcp from any to ${ip} 143 setup
${fwcmd} add allow tcp from any to ${ip} 993 setup
${fwcmd} add allow tcp from any to ${ip} 110 setup
${fwcmd} add allow tcp from any to ${ip} 995 setup
# Deny inbound auth, netbios, ldap, and Microsoft's DB protocol
# without logging.
${fwcmd} add reset tcp from any to ${ip} 113 setup
${fwcmd} add reset tcp from any to ${ip} 139 setup
${fwcmd} add reset tcp from any to ${ip} 389 setup
${fwcmd} add reset tcp from any to ${ip} 445 setup
# Deny some chatty UDP broadcast protocols without logging.
${fwcmd} add deny udp from any 137 to any
${fwcmd} add deny udp from any to any 137
${fwcmd} add deny udp from any 138 to any
${fwcmd} add deny udp from any 513 to any
${fwcmd} add deny udp from any 525 to any
# Allow inbound DNS and NTP replies. This is somewhat of a hole,
# since we're looking at the incoming port number, which can be
# faked, but that's just the way DNS and NTP work.
${fwcmd} add allow udp from any 53 to ${ip}
${fwcmd} add allow udp from any 123 to ${ip}
# Allow inbound DNS queries.
${fwcmd} add allow udp from any to ${ip} 53
# Allow inbound NTP queries.
${fwcmd} add allow udp from any to ${ip} 123
# Allow traceroute to function, but not to get in.
${fwcmd} add unreach port udp from any to ${ip} 33435-33524
# Allow some inbound icmps - echo reply, dest unreach, source quench,
# echo, ttl exceeded.
${fwcmd} add allow icmp from any to any icmptypes 0,3,4,8,11
# Everything else is denied and logged.
${fwcmd} add deny log all from any to any
<?php
// start output buffer
ob_start();
// display the contents of your variable
print_r($YOURVARIABLE);
// get the contents of the output buffer
$ob = ob_get_contents();
// stop output buffer
ob_end_clean();
// mail contents of output buffer to yourself
mail('YOUREMAIL','Output Buffer Contents',$ob);
?>
<?php
$link = mysql_connect("localhost", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE");
$query = "SELECT * FROM TABLENAME";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result))
{
foreach ($line as $value)
{
print "$value\n";
}
}
mysql_close($link);
?>
This was by far the easiest step in my optimization process. To optimize PHP, I used the software called eAccelerator. Compared to all of the other steps, this one had the best ROI for me.
When a PHP script is executed, the PHP interpreter will spend some time interpreting the script then compile the interpretations into opcodes for execution. eAccelerator will precompile your PHP code into ready executable opcodes and manage that opcode cache for you. If your PHP script does not change, Apache will directly call the precompiled opcodes (saving interpretation and compilation time).
This is what I did to set it up:
1) Port install eAccelerator
cd /usr/ports/www/eaccelerator; make install clean
2) Inject these lines into /usr/local/etc/php.ini
; eAccelerator Stuff
;extension="eaccelerator.so"
zend_extension="/usr/local/lib/php/20060613/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.allowed_admin_path = "/usr/local/www/apache22/data"
3) Make cache directory writable
mkdir /tmp/eaccelerator
chown www /tmp/eaccelerator
chmod 0700 /tmp/eaccelerator
4) Restart Apache
/usr/local/etc/rc.d/apache22 restart
That’s it! This 10 minute optimization slashed my page generation time by 25%! But if that’s still not fast enough for you, I will show you how to do Proxy Caching next.