PHP
Jump to navigation
Jump to search
Opcode Cache
Zend OPcache is preferred. Other opcode caches are/were:
- eAccelerator
- APC
- XCache
And they conflict with each other, so check:
php -m | grep -i -E "eaccelerator|apc|xcache|zend"
PHP handlers that can use opcache: DSO (mod_php), FCGI, PHP-FPM
PHP handlers that cannot use opcache: CGI, SuPHP
PECL & PEAR
Use PEAR to install PECL extensions for PHP, if they're not offered in the repos.
CLI how-to: https://pear.php.net/manual/en/guide.users.commandline.commands.php
PHP Examples
PHP pages need to be owned by the user, within the docroot, and accessed via browser.
Test Page
<?php Echo "This is only a test"; ?>
Test Page that shows the server's IP
<?php Echo "This is only a test. <br />"; echo "This server's IP: " . $_SERVER['SERVER_ADDR']; ?>
PHPinfo page
<?php // Show all information, defaults to INFO_ALL phpinfo(); ?>
Show site user's IP address
<?php echo $_SERVER['REMOTE_ADDR' ?>
Show date in the default time zone
<?php
echo " " . date("j-M-Y G:i:s e");
echo " \n";
?>
Cron test
<?php
echo "The time is " . date("h:i:sa");
echo PHP_EOL ;
?>
Then set up a cron job like this:
*/5 * * * * /usr/local/bin/php /home/USER/crontest/phpcron.php >> /home/USER/crontest/phpcronlog.log
List installed classes in alphabetical order
<?php $classes = get_declared_classes(); sort($classes); print_r($classes); ?>
Basic PHP mail test
<?php $to = 'lwtest2@WHATEVER.com'; $subject = 'Test e-mail using PHP'; $message = 'This is a test e-mail message'; $headers = 'From: lwtest@WHATEVER.com' . "\r\n" . 'Reply-To: lwtest@WHATEVER.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers, '-flwtest@WHATEVER.com'); ?>
PEAR Mail test with SMTP Auth & SSL
- Make sure PEAR Mail is installed.
- Make sure that /usr/local/lib/php (on EA3 servers) is in the include path.
- Change the username, password, and host.
<?php require_once "Mail.php"; $from = "LW Test <lwtest@whatever.com>"; $to = "Jim Murphy <jmurphy@liquidweb.com>"; $subject = "Advanced PHP Mail Test"; $body = "Hello,\n\nThis is a test of the PEAR mail system.\n\nThis is only a test."; $host = "ssl://hostname"; $port = "465"; $username = "smtp_username"; $password = "smtp_password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("" . $mail->getMessage() . "
"); } else {
echo("Message successfully sent!
");} ?>