diff --git a/README.md b/README.md index 939a61a..cc03166 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,10 @@ ### Installation -------- -Currently the project contains only one file. Simply add it to your project. +Currently the project contains only one file. Simply add sysVcom.php to your project. Other files are for testing. +The global files need to be set correctly for your project. In particular, a file needs to be created which is +used as the buffer for the SysV system. In practice this is just used as a unique key but it must exist and be +reachable by both client and server. The following methods are use to invoke an RPC
diff --git a/listen-ipc.php b/listen-ipc.php
new file mode 100644
index 0000000..cfb4054
--- /dev/null
+++ b/listen-ipc.php
@@ -0,0 +1,23 @@
+
diff --git a/listen-rpc.php b/listen-rpc.php
new file mode 100644
index 0000000..6b19038
--- /dev/null
+++ b/listen-rpc.php
@@ -0,0 +1,29 @@
+
diff --git a/make-ipc.php b/make-ipc.php
new file mode 100644
index 0000000..b2844c4
--- /dev/null
+++ b/make-ipc.php
@@ -0,0 +1,28 @@
+
diff --git a/make-rpc.php b/make-rpc.php
new file mode 100644
index 0000000..e685bae
--- /dev/null
+++ b/make-rpc.php
@@ -0,0 +1,26 @@
+ 3.14159,
+	'key_2' => "pony"
+);
+
+$cnt = 10000;
+$st_time = (float)getTimeAsString(1733051170);
+for( $i=0; $i<$cnt; $i++){
+	$obj = rpc( 'myFunct', 34, 4.9e-7, $some_arr );
+}
+//print_r( $obj );
+$en_time = (float)getTimeAsString(1733051170);
+
+echo "done\n\n";
+echo (($en_time-$st_time)/$cnt) . "\n\n";
+
+// timed on a laptop (1.9GHz, 2-core, 4-threads) at 30uS per rpc call-return
+// including a short array object
+
+?>
diff --git a/sysVcom.php b/sysVcom.php
new file mode 100644
index 0000000..c4e1c2d
--- /dev/null
+++ b/sysVcom.php
@@ -0,0 +1,227 @@
+0 for a specific message ID.
+ */
+function IPC_rcv( $queue, $rqd_msg_id, &$msgArr, $bBlock = true ){
+
+	$message = '';
+	$received_message_type = 0;
+	
+	while(true){
+				
+		global $g_max_rcv;
+
+		$flags = 0;
+		if(!$bBlock){
+			$flags = MSG_IPC_NOWAIT;
+		}
+		if( FALSE === msg_receive( $queue, $rqd_msg_id, $received_message_type, $g_max_rcv, $message, true, $flags, $error_code ) ){
+			if(!$bBlock && $error_code==MSG_ENOMSG){
+				return 0;
+			}
+			//code 7 when g_max_rcv is too small
+			throw new Exception("Failed to rcv message err = $error_code");	
+		}
+		
+		//echo "Got msg part " . substr( $message, 0, 20 ) . "\n\n";
+		
+		$d_meta = substr( $message, 0, 2 );
+		$message = substr( $message, 2 );
+	
+		if( $msgArr!=null && array_key_exists( $received_message_type, $msgArr) ){
+			$msgArr[ $received_message_type ]['msg'] .= $message;
+			
+		}else{
+			$msgArr=array();
+			$msgArr[ $received_message_type ] = array( 'final' => false, 'msg' => $message );
+		}
+
+		if($d_meta=='f:'){
+			// final message part
+			$msgArr[ $received_message_type ]['final'] = true;
+			break;
+		}
+					
+	}
+
+	return $received_message_type;
+
+}
+
+
+/**
+ * Send a data string of any length.
+ * 
+ * */
+function IPC_send( $queue, $caller_id, $str_data ){
+	
+	//print_r( msg_stat_queue($queue) );
+	
+	global $procName;
+	global $g_k_caller;
+	global $g_k_reply;
+	global $g_max_data;
+
+	$d_meta = null;
+	$chunk_cnt = 0;
+
+	if( strlen($str_data) > $g_max_data ){
+		//split the data into chunks
+		$chunk_cnt = intdiv( strlen($str_data), $g_max_data );
+		$d_meta = "p:";	//partial data - many calls
+	}
+
+	$str_chunk = null;
+	while( $chunk_cnt>=0 ){
+
+		if($chunk_cnt>0){
+			$str_chunk = substr( $str_data, 0, $g_max_data );
+			$str_data = substr( $str_data, $g_max_data );
+		}else{
+			$d_meta = "f:";	//'final' part of data
+			$str_chunk = $str_data;
+		}
+
+		//echo "send($caller_id) len = ".strlen($d_meta.$str_chunk)."\n";
+		
+		$error_code = 0;
+		if( FALSE === msg_send( $queue, $caller_id, $d_meta.$str_chunk, true, true, $error_code ) ){
+			//code 22 when the message is too large
+			throw new Exception("Failed to send message err = $error_code");
+		}
+		$chunk_cnt--;
+		if($chunk_cnt==0){
+			$d_meta = "f:";	//final data chunk
+		}
+	}
+	
+}
+
+?>
diff --git a/time.php b/time.php
new file mode 100644
index 0000000..644a8cd
--- /dev/null
+++ b/time.php
@@ -0,0 +1,18 @@
+