PHP etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
PHP etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

PHP Redis Artırma ve Azaltma

 PHP Redis Artırma ve Azaltma Komutları: Sayısal Değerleri Verimli Şekilde İşleme



Redis: COUNTER, INCR, DECR, INCRBY, DECRBY

<?php
try{
$redis = new Redis();
$redis->connect('redis');
$redis->auth('mypassword');

$redis->set("counter",0);

$redis->incr("counter");//1 incr artırma komutu
$counter = $redis->get("counter");
echo "counter value: ".$counter."<br>";

$redis->incr("counter");//2 incr artırma komutu
$counter = $redis->get("counter");
echo "counter value: ".$counter."<br>";

$redis->decr("counter");//1 decr azaltma komutu
$counter = $redis->get("counter");
echo "counter value: ".$counter."<br>";

$redis->incrby("counter",15);//16 incrby artırmak istedğimiz değer kadar artırır komutu
$counter = $redis->get("counter");
echo "counter value: ".$counter."<br>";

$redis->incrby("counter",5);//21 incrby artırmak istedğimiz değer kadar artırır komutu
$counter = $redis->get("counter");
echo "counter value: ".$counter."<br>";

$redis->decrby("counter",10);//11 decrby azaltmak istedğimiz değeri kadar azaltır komutu
$counter = $redis->get("counter");
echo "counter value: ".$counter."<br>";
}
catch (Exception $e){
echo $e->getMessage();
}
?>

PHP Redis Veri Deploma, Veri Doğrulama

 PHP Redis Veri Deploma, Veri Doğrulama


Redis: SET, GET, EXISTS

<?php
try{
$redis = new Redis();
$redis->connect('redis', 6379);
$redis->auth('mypassword');

$redis->set("user_name", "ali_veli"); //atama işlemi

if($redis->exists('user_name')){ //böyle bir değer varmı
echo "get key user_name to value :" .$redis->get("user_name"); //getir
}
}
catch (Exception $e){
echo $e->getMessage();
}
?>

Serialize ve Unserialize PHP

Serialize ve Unserialize  PHP

serialize — bir array  verisinin saklanabilir olarak string'e çevirip verir.

unserialize — serialize olmuş bir değeri tekrar eski array türüne çevirmek için kullanılır.

<?php
$data = serialize(array("Red", "Green", "Blue"));

echo $data . "<br>";
#a:3:{i:0;s:3:"Red";i:1;s:5:"Green";i:2;s:4:"Blue";}
$test = unserialize($data);
var_dump($test);
#array(3) { [0]=> string(3) "Red" [1]=> string(5) "Green"
# [2]=> string(4) "Blue" }
?>

Örnek Exception Throw PHP

 PHP Örnek Exception Throw 


Php ile örnek throw komutu ,Exception sınıfını miras alarak istediğimiz hata sınıfı oluşturabilir ve catch blogu içerisinde bu hataları daha detaylı gösterebilir ve özelleştirebiliriz. 

<?php
class customException extends Exception{ }

class fruit
{
public function test()
{
if ('a' == 'b') {
throw new customException("error: denk değildir");
} else {
return true;
}
}
}

try {
$a = new fruit();
echo $a->test();
}
catch (customException $e){
print_r($e->getMessage());
}

SoapClient WSA Action To Hatası Çözümü PHP

Php SoapClient WSA Action To Hatası

Hata mesajı:
errors:

1) The message with To '' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher.  Check that the sender and receiver's EndpointAddresses agree.

2) The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/SoapService/login'

Php ile bir başka servise soap isteği atıldığında aşağıdaki gibi bir hata alınıyor ise soap header da action ve to parametreleri eklenerek soap servisin yollu belirtilmelidir. daha sonra soap servis methoduna istek atıldığında headerBody de birleştirilip gönderilmeldir.


<?php
ini_set("soap.wsdl_cache_enabled","0");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


$url = 'http://test.com/SoapService.svc?wsdl';//change
$client = new SoapClient($url,array('soap_version' => SOAP_1_2,
'trace' => 1,'exceptions'=> false));

$wsa_namespace = 'http://www.w3.org/2005/08/addressing';
$NS_ADDR = 'http://www.w3.org/2005/08/addressing';
$ACTION_ISSUE = 'http://tempuri.org/SoapService/login';//change
$ACTION_ADDR = 'http://test.com/SoapService.svc';//change

$action = new SoapHeader($NS_ADDR, 'Action', $ACTION_ISSUE, true);
$to = new SoapHeader($NS_ADDR, 'To', $ACTION_ADDR, false);

$headerbody = array('Action' => $action,'To' => $to);
$client->__setSoapHeaders($headerbody);

$parameters = array('username'=>'abc','password'=>'123');//change
$result = $client->__soapCall('login',$parameters);//change

echo '<pre>';print_r($result);exit();


soapUI 

ilgili method açılarak  alt menuden WS-A menusu açılır ve görseldeki görüntü gelir.

action ve to daki alanlar soap servisin url ile doldurulur.

action: http://tempuri.org/SoapService/login

to: soap-servis-url/SoapService.svc




Yararlı Kodlar 2 PHP

     Yararlı Kodlar 2


PHP de bilinmesi gereken yararlı kodlar.

function_exists:proje içinde fonksiyon varmı, yokmu kontrol eden kod
class_exists:Class varmı yokmu kontrol eden kod
method_exists:Class içinde method varmı yokmu kontrol eden kod
property_exists:Class içinde property varmı yokmu kontrol eden komut
is_subclass_of:Class 'ın içinde miras alınan bir class varmı yokmu kontrol eden komut'
interface_exists:interface varmı yokmu kontrol eden komut
trait_exists:trait varmı yokmu kontrol eden komut
is_a:değişken hangi class 'dan türüdüğünü kontrol etmek için kulanılan kod
extension_loaded:Varolan eklentileri kontrol etmek için kullanılır.