Archive for the 'Php' Kategori

Bir döngüde birden fazla TR yazdırıyyorsanız ve hepsinin ayni fon rengine sahip olmasını istiyorsanız smarty cycle'ı assignile beraber kullanın.

HTML:
  1. {foreach from=$data key=k item=i}
  2.     {cycle values="#EFEFEF,#DEDEDE" assign="bgcolor"}
  3.     <tr bgcolor="{$bgcolor}">
  4.         <td>1</td>
  5.     </tr>
  6.     <tr bgcolor="{$bgcolor}">
  7.         <td>2</td>
  8.     </tr>
  9. {/foreach}

JavaScript ile tablo TR lerini gözter/gizle yapıyorum ama nedense bazen tablo şekli bozuluyor. Bu işin sırrı şurada imiş :

JavaScript:
  1. function kategori_gizle_goster(i) {
  2.         if (i == 1) {
  3.             document.getElementById('kategori_tr').style.display = 'none';
  4.         }
  5.         if (i==2) {
  6.             document.getElementById('kategori_tr').style.display = 'table-row';
  7.         }
  8.     }

style.display = 'table-row' şeklinde tekrar gösterirseniz sorun çıkmıyor.

Arama sonuçlarında aranan kelimenin fon rengini javascrip ile değiştirmek istiyorsanız jQuery ve hilight eklentisini kullanabilirsiniz.
jQuery
hilight eklentisi

Örnek Kod :

HTML:
  1.  
  2.     .highlight { background-color: yellow }
  3. </style>
  4.  
  5. <script type="text/javascript" src="jquery-1.2.6.min.js"></script>
  6. <script type="text/javascript" src="jquery.highlight-2.pack.js"></script>
  7.  
  8. </head>
  9. <div id="highlight-plugin">
  10.     Işık Tut <br>
  11.     bu satırlar ara satırlar :) <br>
  12.     Işık Tut <br>
  13.     bu satırlar ara satırlar :) <br>
  14.     Işık Tut <br>
  15.     bu satırlar ara satırlar :) <br>
  16. </div>
  17.  
  18. <a href="javascript:void($('#highlight-plugin').removeHighlight().each(function() { $.highlight(this, 'IŞIK TUT')}))">Işık Tut</a>
  19.  
  20. <a href="javascript:void $('#highlight-plugin').removeHighlight();">Normal Yap</a>
  21.  
  22. <script type="text/javascript">
  23. <!-- eger sayfa acılır açılmaz ışık tutmak istiyorsanız aşağıdaki kodu yazın -->
  24. $(document).ready(function(){
  25.     $('#highlight-plugin').removeHighlight().each(function() { $.highlight(this, 'BU SATIRLAR ARA SATIRLAR :)')})
  26. });
  27. </script>
  28.  
  29. </body>
  30. </html>

memcache.inc.php
ekte :

PHP:
  1. <?php
  2. /**
  3. * versiyon 2.0  <25.11.2008>
  4. * Ayhan BARIŞ  <info...ayhanbaris.com>
  5. * MySQL entegre edilmiş hali
  6. * memcache hakkında bilgileri MySQL e yazar
  7. * böylece MySQL den select çekerek belirli bir key grubu silinebilir yada bilgileri gösterilebilir
  8. * mesela  WHERE key LIKE 'user_%' gibi bir sorgu ile gelen değerleri toplu olarak mymemcache_delete e gönderilebilir.
  9. * yada o key şu anda memcachede mi diye sorgulanabilir.
  10. **/
  11.  
  12. /**
  13. CREATE TABLE `memcache_status` (
  14.   `id` int(10) unsigned NOT NULL auto_increment,
  15.   `key` varchar(255) NOT NULL,
  16.   `set_time` int(11) unsigned NOT NULL,
  17.   `expire` int(11) unsigned NOT NULL,
  18.   `size` int(10) unsigned NOT NULL,
  19.   PRIMARY KEY  (`id`)
  20. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='hafizadaki memcache durumu' AUTO_INCREMENT=1 ;
  21. **/
  22.  
  23. /**
  24. * memcache 'den data alir
  25. *
  26. * @param string $key
  27. * @return string
  28. */
  29. function mymemcache_get($key) {
  30.         if (class_exists(Memcache)) {
  31.                 global $config;
  32.                 if ( $config["debug"] == 1 ) {
  33.                         return false;
  34.                 }
  35.                 @$memcache = new Memcache;
  36.                 @$memcache->pconnect($config['memcache_host'], $config['memcache_port']);
  37.                 @$template = $memcache->get($key);
  38.                 @$memcache->close();
  39.                 return $template;
  40.         }
  41. }
  42.  
  43. /**
  44. * memcache 'e data gonderir, set eder
  45. * $flag true ise memcache 'e set edilecek datayi zlib ile compress eder.
  46. *
  47. * @param string $key
  48. * @param data $value
  49. * @param boolean $flag
  50. * @param integer $expire
  51. */
  52. function mymemcache_set($key, $value, $flag=false, $expire=900) {
  53.         if (class_exists(Memcache)) {
  54.                 global $config,$db;
  55.                 $memcache = new Memcache;
  56.                 $memcache->pconnect($config['memcache_host'], $config['memcache_port']);
  57.                 $memcache->set($key, $value, $flag, $expire);
  58.                 $memcache->close();
  59.  
  60.                 # memcache_status e işle
  61.                 $set_time=time();
  62.                 $size= round(sizeof($value) / 1024) ; # kb
  63.                 $SQL="SELECT id FROM memcache_status WHERE `key`='$key' ";
  64.                 $sorgu = $db->Execute($SQL);
  65.                 if($sorgu->RecordCount() == 0) {
  66.                     $SQL2="INSERT INTO memcache_status SET `key`='$key' , set_time='$set_time' , expire='$expire' , size='$size'  ";
  67.                 }
  68.                 else {
  69.                     $SQL2="UPDATE memcache_status SET set_time='$set_time' , expire='$expire' , size='$size'  WHERE `key`='$key' ";
  70.                 }
  71.                 $sorgu2 = $db->Execute($SQL2);
  72.         }
  73. }
  74.  
  75. /**
  76. * memcache'den key i verilen datayi siler.
  77. *
  78. * @param string $key
  79. * @return boolean
  80. */
  81. function mymemcache_delete($key) {
  82.         if (class_exists(Memcache)) {
  83.                 global $config,$db;
  84.                 $memcache = new Memcache;
  85.                 $memcache->pconnect($config['memcache_host'], $config['memcache_port']);
  86.                 $action = $memcache->delete($key);
  87.                 $memcache->close();
  88.  
  89.                 # memcache_status e işle
  90.                 $SQL2="DELETE FROM memcache_status WHERE `key`='$key' LIMIT 1 ";
  91.                 $sorgu2 = $db->Execute($SQL2);
  92.  
  93.                 return $action;
  94.         }
  95. }
  96.  
  97. /**
  98. * memcache server hakkinda istatistiksel veriler gosterir.
  99. *
  100. * @return array
  101. */
  102. function mymemcache_getStats() {
  103.         if (class_exists(Memcache)) {
  104.                 global $config;
  105.                 $memcache = new Memcache;
  106.                 $memcache->pconnect($config['memcache_host'], $config['memcache_port']);
  107.                 $stats = $memcache->getStats();
  108.                 $memcache->close();
  109.                 return $stats;
  110.         }
  111. }
  112.  
  113. /**
  114. * memcache'deki tum verileri siler.
  115. *
  116. * @return boolean
  117. */
  118. function mymemcache_flush() {
  119.         if (class_exists(Memcache)) {
  120.                 global $config,$db;
  121.                 $memcache = new Memcache;
  122.                 $memcache->pconnect($config['memcache_host'], $config['memcache_port']);
  123.                 $action = $memcache->flush();
  124.                 $memcache->close();
  125.  
  126.                 # memcache_status e işle
  127.                 $SQL2="TRUNCATE TABLE memcache_status ";
  128.                 $sorgu2 = $db->Execute($SQL2);
  129.  
  130.                 return $action;
  131.         }
  132. }
  133. ?>

Memcache 'li programlama yapısında genelde şu mantık kullanılır:

PHP:
  1. $kayit = $memcache->get( 'yorum_sayisi' . $resim_id );
  2. if( !$kayit ) {
  3. $kayit = 0; # db den gelen veri 0 olsun
  4. $memcache->set('yorum_sayisi' . $resim_id , $kayit, false, 10);
  5. }

Ama siz bu yapıyı kullanmayın !
Bunun yerine :

PHP:
  1. $kayit = $memcache->get( 'yorum_sayisi' . $resim_id );
  2. if( $kayit === false ) {
  3. $kayit = 0; # db den gelen veri 0 olsun
  4. $memcache->set('yorum_sayisi' . $resim_id , $kayit, false, 10);
  5. }

kullanın.
Sebebine gelince ; Memcache de sayisal veri tutuyorsanız, ki bu örnekte resmin yorum sayisini db 'den çekip memcache yazdığımızı varsayalim.
İlk yapı hatalı çalışacaktır. Çünkü yorum sayısı 0 olan  bir resim için !$kayit ifadesi herzaman true olur ve memcache istediğimiz gibi çalışmaz.

PHP Manual
PEAR Manual
PHP-GTK Manual
Smarty Manual
PostgreSQL Manual
CSS 2 Reference
Redhat Linux 9
HTML 4.01
Apache 2 Manual

memcached şu anda arka planda çalışıyor mu kontrol etmek için :

PHP:
  1. function is_running_memcache() {
  2. $ret = false;
  3. exec("ps -e | grep memcached ",$output);
  4. if(!empty($output)) {
  5. $ret = true; # calişiyor
  6. }
  7. return $ret;
  8. }

Bilgisayarımı açtım, ufak ufak kod yazmaya da başladım. Bugün farkettim ki Edit Plus 'ı 999 gündür kullanıyormuşum :) işte resmi aşağıda...

edit plus

Xajax  birçok fonksiyon register etmek yerine sadece bir tane EmirKULU'nuz olsun. Siz yapılaca işi ve işlenecek veriyi EmirKULU'nuza verin gerisini o halletsin.

<?php
define("DEFAULT_CHARSET" , 'iso-8859-9');

require_once("xajax_core/xajax.inc.php");

$xajax = new xajax();
$xajax->setCharEncoding(DEFAULT_CHARSET);

function emirKulu($is,$veri) {
global $objResponse,$newContent;

$newContent="";
$objResponse = new xajaxResponse(DEFAULT_CHARSET);

switch($is) {
case 'sari': sari($veri);
break;
case 'yesil': yesil($veri);
break;
default : isYok($veri);
}

return $objResponse;
}

function sari($veri) {
foreach($veri as $n => $v){$$n = $v;}
global $objResponse,$newContent;
$newContent="sari = $sayi";
$objResponse->assign("yer","innerHTML",$newContent);
}

function yesil($veri) {
foreach($veri as $n => $v){$$n = $v;}
global $objResponse,$newContent;
$newContent="yesil = $sayi";
$objResponse->assign("yer","innerHTML",$newContent);
}

$xajax->registerFunction("emirKulu");
$xajax->processRequest();

?>

<html>

<head>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="history" content="">
<meta name="author" content="Verdana Core, phpdoc.net Inc.">
<title></title>
<?php $xajax->printJavascript(); ?>
</head>

<body>

<div id="yer">burası degisecek</div>

<form method=post action="" id="form1">
<input type="text" name="sayi" value="5">
</form>

<input type="button" onclick="xajax_emirKulu('sari',xajax.getFormValues('form1'));" value="Sari">
<input type="button" onclick="xajax_emirKulu('yesil',xajax.getFormValues('form1'));" value="Yeşil">

</body>

</html>

Yüksek performanslı, dağıtık, nesne tabanlı önbellekleme yazılımıdır. Linux serverda bir servis olarak çalışır. PHP,C,PERL vb. programlama dilleri API ile Memcached 'e erişerek veri depolatabilirler.
Genellikle dinamik web uygulamalarını hızlandırmak amacı ile kullanılır.

SQL sorgu sonucunu veya Php 'nin oluşturduğu Html sayfayı memcached 'de depolayabilirsiniz.
Böylece web sitesi ram'den çalışırmışcasına hızlı açılır, aynı Sql sorgularını ve Php komutlarını tekrar tekrar çalıştırmaz, ön bellekten okuyarak ziyaretçiye/istemciye sunar.

Web sitelerinde kullanım yerleri olarak ;
- Sık ziyaret edilen sayfalar. Detay Sayfaları, Ana Sayfa, Arama Sonuç...
- Session bilgilerinin tutulması.
- Sık kullanılan ve veritabanından gelen veriler/diziler/objeler.
(more...)