Thank you DrByte
but I prefer to Fix the Problem instead Switching module.
ok this class will let us to process multiple txn_id's Serial so there wont be "race condition" any more. if it succeed i will share the result.
PHP Code:
class process_filelock {
protected $process_id;
protected $category;
protected $additional="Dummy Text";
protected $process_unq_id;
protected $active_status_code='ACTIVE';
protected $file_path='';
protected $fp;
function __construct() {
$this->set_file_path();
register_shutdown_function(array(&$this, "unlock"));
}
function get_file_path(){
return $this->file_path;
}
protected function get_file() {
return $this->file_path.$this->category.'_'.$this->process_id.'.lock';
}
protected function set_file_path() {
if(defined(DIR_FS_CATALOG)){
$this->file_path=DIR_FS_CATALOG.'cache/';
}else{
$this->file_path='cache/';
}
if (!is_dir($this->file_path)) {
mkdir($this->file_path,0700,true);
}
}
function lock($process_id,$category='DEFAULT',$additional=''){
$this->process_id=$process_id;
$this->category=$category;
$this->additional=$additional;
$file=$this->get_file();
$this->fp = fopen( $file,"a"); // open it for WRITING ("w")
if (!$this->fp){
return false;
}
if (flock($this->fp, LOCK_EX)) {
// do your file writes here
fwrite($this->fp, date("H:i:s", time())." Lock defined on file. \n".$this->additional."\n");
return true;
} else {
return false;
}
}
protected function __destruct() {
$this->unlock();
}
function unlock() {
fwrite($this->fp, date("H:i:s", time())." Lock Released on file. \n");
$ret=flock($this->fp, LOCK_UN);
fclose($this->fp);
return $ret;
}
}
class process_paypal_filelock extends process_filelock{
protected function set_file_path() {if(defined(DIR_FS_CATALOG)){
$this->file_path=DIR_FS_CATALOG.'includes/modules/payment/paypal/locks/';
}else{
$this->file_path='includes/modules/payment/paypal/locks/';
}
if (!is_dir($this->file_path)) {
mkdir($this->file_path,0700,true);
}
}
}
insert following code after following line
require('includes/application_top.php');
PHP Code:
require('includes/classes/process_lock.php');
$lock=new process_paypal_filelock();
$lock->lock($_POST['txn_id'],"PAYPAL_IPN","Note");
Bookmarks