Hiển thị các bài đăng có nhãn PHP. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn PHP. Hiển thị tất cả bài đăng

Thứ Hai, 19 tháng 5, 2014

Check how much memory your PHP script is using

Check how much memory your PHP script is using?


The answer is the memory_get_peak_usage() function.

At the end of your PHP script (footer script for a PHP site, you get the idea), put this line:
echo memory_get_peak_usage();
Or you can write the data down in a text file:
file_put_contents('mu.txt', memory_get_peak_usage());
The output is in bytes.More friendly output,Add to the footer of the templates:
<?php
function convert($size) {
   $unit=array('b','kb','mb','gb','tb','pb');
   return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
echo convert(memory_get_peak_usage(true));
?>
Read More

Thứ Tư, 12 tháng 3, 2014

Update PHP 5.3 for Kloxo

Update PHP 5.3 for Kloxo

You can follow the steps below to update your php version to 5.3  for Kloxo.

Install repository

Creat file /etc/yum.repos.d/ius.repo

[ius]
name=IUS Community Packages for Enterprise Linux 5 - $basearch
baseurl=http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/$basearch
enabled=1
gpgcheck=0

Creat file /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
enabled=1
gpgcheck=0
exclude=nginx*

Install yum replace 

yum install yum-plugin-replace
Replace php with php53u
yum replace php --replace-with=php53u
 * Other way: remove php and install php53u
yum -y remove php php-common
yum -y install php53u php53u-cli php53u-devel php53u-gd php53u-imap php53u-mbstring php53u-mysql php53u-pdo php53u-pear php53u-xml
 Create a php.ini template for php5.3
# cp /usr/local/lxlabs/kloxo/file/phpini/php.ini.template-5.2 /usr/local/lxlabs/kloxo/file/phpini/php.ini.template-5.3
# chown -R lxlabs:lxlabs /usr/local/lxlabs/kloxo/file/phpini/php.ini.template-5.3
Verify the new PHP version.
# php -v
Read More

Thứ Năm, 30 tháng 5, 2013

PHP FCGI


A default installation of FastCGI on cPanel server is dangerously simple. It’s dangerous because one cPanel account (or one vhost) is capable of crashing down a whole server if, say, traffic were to spike up. It’s also simple because it won’t allow complex scripts to run cleanly. In brief, it’s absolutely not ready for production as-is. In this post, I’ll go over what it takes to configure FastCGI on a cPanel node properly.
The following is a list of settings that you need to add to /etc/httpd/conf/php.conf upon switching to FastCGI:
MaxRequestsPerProcess 1000
FcgidMaxProcesses 200
FcgidProcessLifeTime 7200
MaxProcessCount 500
FcgidIOTimeout 400
FcgidIdleTimeout 600
FcgidIdleScanInterval 90
FcgidBusyTimeout 300
FcgidBusyScanInterval 80
ErrorScanInterval 3
ZombieScanInterval 3
DefaultMinClassProcessCount 0
DefaultMaxClassProcessCount 3
MaxRequestLen 20468982
You’re more likely to adjust the settings in bold above. DefaultMinClassProcessCount 0 instructs FastCGI to keep zero PHP processes running for user when traffic is idle (cPanel account user) . On the other hand, DefaultMaxClassProcessCount 3 tells FastCGI to never allow more than 3 PHP processes running at a time. This settings prevents one users from crashing the server were they to receive a lot of traffic.
So go ahead and copy/paste the above into your httpd.conf and restart Apache (service httpd restart). You’re good to go now!
Distill and rebuild Apache, then restart Apache
root@server[#] /usr/local/cpanel/bin/apache_conf_distiller --update
root@server[#] /scripts/rebuildhttpdconf
root@server[#] /etc/init.d/httpd restart

/etc/httpd/conf/php.conf

# Fastcgi configuration for PHP5
LoadModule fcgid_module modules/mod_fcgid.so
MaxRequestsPerProcess 500
DefaultMinClassProcessCount 0
DefaultMaxClassProcessCount 2
MaxRequestLen 204689820
FcgidConnectTimeout 150
FcgidIdleScanInterval 90
FcgidIOTimeout 150
AddHandler fcgid-script .php5 .php4 .php .php3 .php2 .phtml
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php5
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php4
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php3
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php2
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .phtml
Read More

Thứ Ba, 14 tháng 5, 2013

How to enable Custom php.ini for PHP FCGI

If you want to enable custom php.ini settings for PHP FCGI on your server then follow the below steps : 

1 > Create a .htaccess file under the directory : /home/username/public_html
root@server[#] cd /home/username/public_html
root@server[/home/username/public_html]# vi .htaccess

And the below two lines at the top :
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi

save and quit.
2 > go to the cgi-bin directory : /home/username/public_html/cgi-bin
root@server[#] cd /home/username/public-html/cgi-bin
and then copy the default php.ini here
root@server[#] cp /usr/local/lib/php.ini /home/username/public_html/cgi-bin/
3 > Create php.fcgi file to load custom php.ini
Please note that you should still be in /home/username/public_html/cgi-bin location.
root@server[/home/username/public_html/cgi-bin] # vi php.fcgi
and then add the below code :
#!/bin/sh
export PHP_FCGI_CHILDREN=1
export PHP_FCGI_MAX_REQUESTS=10
exec /usr/local/cpanel/cgi-sys/php5

save and quit.
Now make the file php.cgi executable:
root@server[/home/username/public_html/cgi-bin] # chmod + x php.fcgi
4 > Change ownership of files to correct user:
root@server[/home/username/public_html/cgi-bin] chown username.username * -R
And if it still does not work for you then follow the below steps as well :
5 > Add paths to php.conf file
root@server[#] vi /usr/local/apache/conf/php.conf
and add the below lines :
Action php5-fastcgi /cgi-bin/php.fcgi
AddType application/x-httpd-php .php

save and quit.
and after adding the above two lines the php.conf file should look like this :
root@server[/usr/local/apache/conf] # cat php.conf
# Fastcgi configuration for PHP5
LoadModule fcgid_module modules/mod_fcgid.so
MaxRequestsPerProcess 500
AddHandler fcgid-script .php5 .php4 .php .php3 .php2 .phtml
Action php5-fastcgi /cgi-bin/php.fcgi
AddType application/x-httpd-php .php
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php5
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php4
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php3
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php2
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .phtml

# End of autogenerated PHP configuration.
6 > Distill and rebuild Apache, then restart Apache
root@server[#] /usr/local/cpanel/bin/apache_conf_distiller –update
root@server[#] /scripts/rebuildhttpdconf
root@server[#] /etc/init.d/httpd restart
And finally to test if the custom php.ini is working follow the steps :

root@server[#] cd /home/username/public_html
root@server[/home/username/public_html]# vi info.php
Add the below lines :
< ?php
phpinfo();
?>

save and quit.
Change the ownership of info.php file to user:user
root@server[/home/username/public_html]# chown username:username info.php
Now browse the URL : http://domain.com/info.php
And search for the line : Loaded Configuration File
Loaded Configuration File /home/username/public_html/cgi-bin/php.ini

Or
Here's a simpler solution:

Edit the file called /usr/local/cpanel/cgi-sys/php5 -- insert the line above exec /usr/bin/php as follows:


Code:
#!/bin/sh

# If you customize the contents of this wrapper script, place
# a copy at /var/cpanel/conf/apache/wrappers/php5
# so that it will be reinstalled when Apache is updated or the
# PHP handler configuration is changed

[ -f ~/php.ini ] && exec /usr/bin/php -c ~/
exec /usr/bin/php 

Copy the file over to /var/cpanel/conf/apache/wrappers/php5 as indicated at the top of the file.

Now, if any account has a php.ini file in their home directory (not public_html) then it will be used instead of the system-provided one.
Read More

Chủ Nhật, 5 tháng 5, 2013

Custom php.ini settings for PHP FCGI



custom php.ini settings for PHP FCGI


If you want to enable custom php.ini settings for PHP FCGI on your server then follow the below steps :

1. Create a .htaccess file under the directory : /home/username/public_html

cd /home/username/public_html
vi .htaccess
Add the below two lines at the top :
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi
save and quit.

2. Go to the cgi-bin directory : /home/username/public_html/cgi-bin

cd /home/username/public-html/cgi-bin
and then copy the default php.ini here
cp /usr/local/lib/php.ini /home/username/public_html/cgi-bin/

3. Create php.fcgi file to load custom php.ini

Please note that you should still be in /home/username/public_html/cgi-bin location.
vi php.fcgi
and then add the below code :
#!/bin/sh
export PHP_FCGI_CHILDREN=1
export PHP_FCGI_MAX_REQUESTS=0
exec /usr/local/cpanel/cgi-sys/php5
save and quit.
Now make the file php.cgi executable:
chmod + x php.fcgi


4. Change ownership of files to correct user:

chown username.username * -R
And if it still does not work for you then follow the below steps as well :

5. Add paths to php.conf file

vi /usr/local/apache/conf/php.conf
and add the below lines :
Action php5-fastcgi /cgi-bin/php.fcgi
AddType application/x-httpd-php .php
save and quit.
and after adding the above two lines the php.conf file should look like this :
root@server[/usr/local/apache/conf] # cat php.conf
# Fastcgi configuration for PHP5
LoadModule fcgid_module modules/mod_fcgid.so
MaxRequestsPerProcess 500
AddHandler fcgid-script .php5 .php4 .php .php3 .php2 .phtml
Action php5-fastcgi /cgi-bin/php.fcgi
AddType application/x-httpd-php .php
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php5
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php4
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php3
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php2
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .phtml
# End of autogenerated PHP configuration.

6. Distill and rebuild Apache, then restart Apache

/usr/local/cpanel/bin/apache_conf_distiller –update
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart
Read More