multithreading - Php cli has stop woriking PHP Pthreads program -


i have huge text file. want write specific lines db file @ specific places. wrote php script ran 17 days. reduce time re-write program using php pthreads multi threaded program. have divided file 100 small files. 100 threads manipulating files separately. program runs fine day command line gives cli has stopped working error.

here specifics:

windows 7 professional service pack 1
processor: intel(r) core(tm) i5
ram: 4 gb
php version: 5.5.12
pthreads version: 2.0.10

this windows log error:

log name: application
source: application error
date: 7/8/2015 7:41:22 am
event id: 1000
task category: (100)
level: error
keywords: classic
user: n/a
computer: ict-db-migr
description:
faulting application name: php.exe, version: 5.5.12.0, time stamp: 0x53613fb5
faulting module name: php5ts.dll, version: 5.5.12.0, time stamp: 0x53614545
exception code: 0xc0000005
fault offset: 0x000000000000ad68
faulting process id: 0x10ec
faulting application start time: 0x01d0b889e4ff1462
faulting application path: c:\wamp\bin\php\php5.5.12\php.exe
faulting module path: c:\wamp\bin\php\php5.5.12\php5ts.dll
report id: a05581e5-2516-11e5-9cc2-a0481c83537b

this php program:

<?php  ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1);  /**  * author:   * url:   */   $time_start = microtime(true);    class threadsafe extends stackable {    public function run(){}  }   class workerthreads extends thread {    private $workerid;    private $conn;         public function __construct($id,$dataarray)     {     $this->workerid = $id;     $this->dataarray2 = $dataarray;     }  public function run() {      include "db_connect.php";       $file_name="breaked_mark_files\usmark_".$this->workerid.".mrk";          $file=fopen($file_name,"r") or exit("unable open file!");             $id=0;     $datacount=-1;     $count852=0;     $datasubcount=0;      while(!feof($file)){              echo 'worker '.$this->workerid." executing line record ".$id."    line number".$datacount."".php_eol;            $line = fgets($file);            $field = substr($line,0,4);         $strlenth = strlen($line);           $data = substr($line,6);              /* if($datacount==1){                 //var_dump($dataarray2);             break;          } */          if($field == "=ldr"){                     $count852=0;             $datacount++;                $datasubcoun=0;                              $this->dataarray2[]=$line;              $datasubcount++;          }elseif($field=="=852"){                  if($count852 == 0){                  $array=explode("\$",$data);                  foreach($array $key=>$value){                      if($key !=0){                          $str = $value;                         $strlength=strlen($str);                         $first_string=substr($str,0,1);                          if($first_string == "p"){                              $id=substr($str,1);                                           }                                 }                  }                  $this->dataarray2[]=$line;                 //$count995++;                 $datasubcount++;                                  }else{                        $this->dataarray2[]=$line;                 $datasubcount++;             }          }else{              $this->dataarray2[]=$line;             $datasubcount++;              }             //$id = intval($id);         $id = mysql_real_escape_string($id);                     $sql = "select languagedata data_table id='$id'";            if($id != 0){                             $result = $conn->query($sql);                         if ($result->num_rows > 0) {                  // output data of each row                 while($row = $result->fetch_assoc()) {                      $this->dataarray2[]=$row["languagedata"];                     $datasubcount++;                  }                                 } else {                 //echo "0 results of main record id  ".$id."".php_eol;             }              $sql = "select holdingdata holding_data record_id='$id'";              $result = $conn->query($sql);              if ($result->num_rows > 0) {                 // output data of each row                 while($row = $result->fetch_assoc()) {                      $this->dataarray2[]=$row["holdingdata"];                     $datasubcount++;                  }                  $id=0;                                } else {                  //echo "0 results of holding data id ".$id."".php_eol;             }          }         }      $conn->close();   } }  // worker pool $workers = []; $array=[];  foreach (range(0, 49) $i){  $array[$i]= new threadsafe();    }  // initialize , start threads  foreach (range(0, 49) $i) {    $workers[$i] = new workerthreads($i,$array[$i]);   $workers[$i]->start(); }  // let threads come foreach (range(0, 49) $i) { $workers[$i]->join(); }     $file=fopen("writtenfle.txt","w") or exit("unable open file!");   $array_count = count($array);   foreach(range(0, ($array_count-1)) $i){   $array_count2 = count($array[$i]);   foreach(range(0, ($array_count2-1)) $y){      fwrite($file,$array[$i][$y]."\r\n");     }  }  fclose($file);  $time_end = microtime(true);  $execution_time = ($time_end - $time_start)/60;  echo 'total execution time: '.$execution_time.' mins'.php_eol; 


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -