레이블이 php인 게시물을 표시합니다. 모든 게시물 표시
레이블이 php인 게시물을 표시합니다. 모든 게시물 표시

2017/12/22

PHP Session handler Redis 설정

Ubuntu 12.04, PHP 5.x 기준

PhpRedis 설치

su
cd /tmp
git clone https://github.com/nicolasff/phpredis.git
cd phpredis
phpize
./configure
make && make install
echo extension=redis.so > /etc/php5/conf.d/redis.ini
php -i | grep -E 'Redis Support|Registered save handlers'
  • Redis Support => enabled 확인
  • Registered save handlers => redis 포함 확인

PHP Session handler 설정 변경

vi /etc/php5/apache2/php.ini
-----------------------------
...
;; 주석처리
;session.save_handler = files
;; 아래 내용 추가
session.save_handler = redis
session.save_path = "tcp://레디스서버IP:포트?auth=패스워드"
...

  • Apache 재시작 후 Redis에 세션 데이터 생성 여부 확인
service apache2 restart



참고: https://github.com/phpredis/phpredis

2015/07/01

[cakephp] .htaccess mod_rewrite edit for exclude folder or url


I making cakephp 3.0 web app.

I want to cakephp exclude url for static html folder.


/app/webroot/exclude/some.html


/app/.htaccess
<IfModule mod_rewrite.c>
    RewriteEngine on    RewriteRule    ^$    webroot/    [L]    RewriteRule    (.*) webroot/$1    [L]</IfModule>

webroot/.htaccess
<IfModule mod_rewrite.c>
    RewriteEngine On    RewriteCond %{REQUEST_URI} !^/exclude/(.*) # add this Line on default    RewriteCond %{REQUEST_FILENAME} !-f    RewriteRule ^ index.php [L]</IfModule>



http://stackoverflow.com/questions/2249885/cakephp-htaccess-mod-rewrite-configuration-to-exclude-a-particular-folder-url

2015/06/24

[php] increase max upload size (wordpress)




PHP_INI_PERDIR Entry can be set in php.ini, .htaccess, httpd.conf or .user.ini (since PHP 5.3)

php.ini

upload_max_filesize = 32M
post_max_size = 32M

then httpd restart




http://stackoverflow.com/questions/13442270/ini-setupload-max-filesize-200m-not-working-in-php

2015/05/13

[php] 기본 페이징 코드


// 전체 게시물수
$totalCnt = $row['cnt'];
// 한 페이지 게시글 수 
$onePagePer = 15;
// 전체 페이지 수
$totalPageCnt = ceil($totalCnt / $onePagePer);
if ($page < 1 && $page > $totalPageCnt) {
?>
 <script type="text/javascript">
 alert('존재하지 않는 페이지 입니다.');
 history.back();
 </script>
<?php
 exit;
}
// 한번에 보여줄 총 페이지 개수
$oneSectionPer = 10;
// 현재 섹션
$currentSection = ceil($page / $oneSectionPer);
// 전체 섹션의 수
$totalSectionCnt = ceil($totalPageCnt / $oneSectionPer);
// 현재 섹션의 처음 페이지
$firstPage = ($currentSection * $oneSectionPer) - ($oneSectionPer - 1);
if ($currentSection == $totalSectionCnt) {
 // 현재 섹션이 마지막 섹션이라면 $totalPageCnt가 마지막 페이지가 된다
 $lastPage = $totalPageCnt;
} else {
 $lastPage = $currentSection * $oneSectionPer;
}
// 이전페이지
$prevPage = (($currentSection - 1) * $oneSectionPer);
// 다음 페이지
$nextPage = (($currentSection + 1) * $oneSectionPer) - ($oneSectionPer - 1);
// 페이징을 저장할 변수
$paging = '<ul>';
// 첫페이지가 아니라면 처음 버튼을 생성
if ($page != 1) {
 $paging .= '<li class="page page_start"><a href="./index.php?page=1">처음</a></li>';
}
// 첫 섹션이 아니라면 이전 버튼을 생성
if ($currentSection != 1) {
 $paging .= '<li class="page page_prev"><a href="./index.php?page=' .$prevPage. '">이전</a></li>';
}

for ($i = $firstPage; $i <= $lastPage; $i++) {
 if ($i == $page) {
  $paging .= '<li class="page current">' .$i. '</li>';
 } else {
  $paging .= '<li class="page"><a href="./index.php?page=' .$i. '">' .$i. '</a></li>';
 }
}
//마지막 섹션이 아니라면 다음 버튼을 생성
if ($currentSection != $totalSectionCnt) {
 $paging .= '<li class="page page_next"><a href="./index.php?page=' .$nextPage. '">다음</a></li>';
}
// 마지막 페이지가 아니라면 끝 버튼을 생성
if ($page != $totalPageCnt) {
 $paging .= '<li class="page page_end"><a href="./index.php?page='.$totalPageCnt.'">끝</a></li>';
}
$paging .= '</ul>';
/* 페이징 끝 */
$currentLimit = ($onePagePer * $page) - $onePagePer;
$sqlLimit = ' LIMIT ' .$currentLimit. ', '.$onePagePer;
$sql = 'SELECT * FROM board_free ORDER BY b_no DESC' .$sqlLimit;
$result = $db->query($sql);