» php の記事

~ Centos7 php7 install pThread ~

connie 2017.03.30 | centos, php | | No Comments
yum install gcc php70w-devel

git clone https://github.com/krakjoe/pthreads.git
cd pthreads
zts-phpize
./configure --with-php-config=/usr/bin/zts-php-config
make

cp modules/pthreads.so /usr/lib64/php-zts/modules/
nano /etc/php-zts.d/pthreads.ini
extension=pthreads.so

Testing for Thread Safety enable

/etc/php-zts.d/pthreads.ini

Should see those thing below
Thread Safety => enabled
pthreads

Execute server-side Script

zts-php -q ws_server.php

instead of using 
php -q 

 

~ Install Mod_GeoIP in centos ~

connie 2016.07.13 | apache | | No Comments
yum update

yum install mod_geoip GeoIP GeoIP-devel GeoIP-data zlib-devel

cd/usr/share/GeoIP/
mv GeoIP.dat GeoIP.dat_org
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz

nano /etc/httpd/conf/httpd.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
</IfModule>
nano /var/www/html/testgeoip.php
<?
var_dump(getenv(GEOIP_COUNTRY_NAME))

 

~ PDO @ php ~

connie 2016.05.19 | php | | No Comments

get assoc array from db ONLY

$rtn= $query->fetchAll(PDO::FETCH_ASSOC);
Array
(
    [hmvID] => 1
    [insertDate] => 2016-03-16 15:18:53
    [requestType] => EAN
    [requestData] => 4547557009859
    [requestDate] => 2016-03-16 17:45:38
    [status] => 1
    [type] => CD
    [title] => ジレンマ(期間生産限定盤)(アニメ盤)
    [artist] => ecosystem
    [ReleaseDate] => 2011-11-30
    [sPhoto] => http://ecx.images-amazon.com/images/I/512THFU3PrL._SL75_.jpg
    [XLPhoto] => http://ecx.images-amazon.com/images/I/512THFU3PrL.jpg
    [ListPrice] => ¥ 1,337
    [LowestNewPrice] => ¥ 570
    [ASIN] => B005OCSU7Y
    [EAN] => 4547557009859
    [SeikodoProductCode] => 
    [DetailPageURL] => http://www.amazon.co.jp/%E3%82%B8%E3%83%AC%E3%83%B3%E3%83%9E-%E6%9C%9F%E9%96%93%E7%94%9F%E7%94%A3%E9%99%90%E5%AE%9A%E7%9B%A4-%E3%82%A2%E3%83%8B%E3%83%A1%E7%9B%A4-ecosystem/dp/B005OCSU7Y%3FSubscriptionId%3DAKIAIMFGLRVRLCPPHX7A%26tag%3Dpuiconnie-22%26linkCo
    [currentStorage] => 房間貓柱CD櫃
    [tag] => 銀魂
)

get assoc and int array from db

$rtn= $query->fetchAll();
Array
(
    [hmvID] => 1
    [0] => 1
    [insertDate] => 2016-03-16 15:18:53
    [1] => 2016-03-16 15:18:53
    [requestType] => EAN
    [2] => EAN
    [requestData] => 4547557009859
    [3] => 4547557009859
    [requestDate] => 2016-03-16 17:45:38
    [4] => 2016-03-16 17:45:38
    [status] => 1
    [5] => 1
    [type] => CD
    [6] => CD
    [title] => ジレンマ(期間生産限定盤)(アニメ盤)
    [7] => ジレンマ(期間生産限定盤)(アニメ盤)
    [artist] => ecosystem
    [8] => ecosystem
    [ReleaseDate] => 2011-11-30
    [9] => 2011-11-30
    [sPhoto] => http://ecx.images-amazon.com/images/I/512THFU3PrL._SL75_.jpg
    [10] => http://ecx.images-amazon.com/images/I/512THFU3PrL._SL75_.jpg
    [XLPhoto] => http://ecx.images-amazon.com/images/I/512THFU3PrL.jpg
    [11] => http://ecx.images-amazon.com/images/I/512THFU3PrL.jpg
    [ListPrice] => ¥ 1,337
    [12] => ¥ 1,337
    [LowestNewPrice] => ¥ 570
    [13] => ¥ 570
    [ASIN] => B005OCSU7Y
    [14] => B005OCSU7Y
    [EAN] => 4547557009859
    [15] => 4547557009859
    [SeikodoProductCode] => 
    [16] => 
    [DetailPageURL] => http://www.amazon.co.jp/%E3%82%B8%E3%83%AC%E3%83%B3%E3%83%9E-%E6%9C%9F%E9%96%93%E7%94%9F%E7%94%A3%E9%99%90%E5%AE%9A%E7%9B%A4-%E3%82%A2%E3%83%8B%E3%83%A1%E7%9B%A4-ecosystem/dp/B005OCSU7Y%3FSubscriptionId%3DAKIAIMFGLRVRLCPPHX7A%26tag%3Dpuiconnie-22%26linkCo
    [17] => http://www.amazon.co.jp/%E3%82%B8%E3%83%AC%E3%83%B3%E3%83%9E-%E6%9C%9F%E9%96%93%E7%94%9F%E7%94%A3%E9%99%90%E5%AE%9A%E7%9B%A4-%E3%82%A2%E3%83%8B%E3%83%A1%E7%9B%A4-ecosystem/dp/B005OCSU7Y%3FSubscriptionId%3DAKIAIMFGLRVRLCPPHX7A%26tag%3Dpuiconnie-22%26linkCo
    [currentStorage] => 房間貓柱CD櫃
    [18] => 房間貓柱CD櫃
    [tag] => 銀魂
    [19] => 銀魂
)

 

~ centos setting GEOIP ~

connie 2016.05.06 | centos, php | | No Comments
yum install GeoIP-devel
yum install php-pear
yum install php-pecl-geoip

cd /usr/share/GeoIP
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoIP.dat.gz
gunzip GeoLiteCity.dat.gz
mv GeoLiteCity.dat GeoIPCity.dat

sudo systemctl restart php-fpm
sudo systemctl restart nginx

TEST PHP CODE

$record = geoip_record_by_name($_SERVER["REMOTE_ADDR"]);
    if ($record) {
        print_r($record);
    }

 

~ php doc generator ~

connie 2013.06.25 | php | | No Comments

Firstly, install the pear

sudo apt-get install php-pear

Install apigen

pear config-set auto_discover 1
pear install pear.apigen.org/apigen

generate the doc

go to the target "web system" folder

apigen --source . --destination docs/apigen --todo yes \
 --title "the api title" --php no 

 

~ php get current directory or filename ~

connie 2013.04.03 | php | | No Comments

目標:

/var/www/connie/test.php

output = "/var/www/connie/test.php"

echo __FILE__;

output = "test.php"

echo basename(__FILE__);

output = "test"

echo basename(__FILE__, '.php');

output = "/var/www/connie"

echo dirname(__FILE__);

output = "/var/www/" (parent folder)

echo dirname(dirname(__FILE__));

~ install mcrypt in ubuntu ~

connie 2013.01.22 | ubuntu | | No Comments
apt-get install php5-mcrypt
/etc/init.d/apache2 restart

 

~ Warning: mysqli_connect(): (HY000/2002) ~

connie 2013.01.18 | php | | No Comments

如果php connect mysql 時出現以下情況

Warning: mysqli_connect(): (HY000/2002): 
No such file or directory in *****.php on line 8 
Warning: mysqli_query() expects parameter 1 to be mysqli, 
boolean given in *****.php on line 9 
Connect failed

只要將connect DB 由localhost 改回127.0.0.1 就可以了

define('DATABASE_SERVER', '127.0.0.1');

 

~ 延長phpmyadmin 的login session 時間 ~

connie 2013.01.10 | php | | No Comments

在config.inc.php 加上或修改以下coding

$cfg['LoginCookieValidity'] = 3600 * 9; // 9 hours

完成

Mac OS X Server Apache 無法存取本機 MySQL Server 解決方式

由 phpinfo 中得知,是將 Mac 中的 PHP 是將 mysql.sock 放在 /var/mysql 下,

而 Mac 中的 MySQL 是放在 /tmp/mysql.sock。

所以要由本機的 Web Server 利用 PHP 連接本機的 MySQL 就會一直出現無法連線的錯誤。

利用底下的指令可以解決這個問題

sudo mkdir /var/mysql
sudo chown mysql /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/
« Previous Page | HOME |