Fatal error: function call undefined sem_get ()

I am new to PHP and I am trying to run the code that I received from someone else on my Windows development machine. I installed PHP 5 and Apache 2.2, but when I try to start it, I get an error message:

Fatal error: Call to undefined function sem_get() 

Drop line:

 private function UpdateCounter($semkey, $memkey, $count) { $sem_h = sem_get($semkey, 1);//this line is the problem ... } 
+6
synchronization windows php semaphore
source share
2 answers

The sem_get() function is provided by Semaphore, shared memory, and IPC .

Quoting introduction in this section:

This extension is not available on Windows.

+9
source share

I don't know if this will work as expected, but I found a workaround for sem_get on Windows :

 if (!function_exists('sem_get')) { function sem_get($key) { return fopen(__FILE__ . '.sem.' . $key, 'w+'); } function sem_acquire($sem_id) { return flock($sem_id, LOCK_EX); } function sem_release($sem_id) { return flock($sem_id, LOCK_UN); } } 

Also, I needed ftok on Windows :

 if( !function_exists('ftok') ) { function ftok($filename = "", $proj = "") { if( empty($filename) || !file_exists($filename) ) { return -1; } else { $filename = $filename . (string) $proj; for($key = array(); sizeof($key) < strlen($filename); $key[] = ord(substr($filename, sizeof($key), 1))); return dechex(array_sum($key)); } } } 
+6
source share

All Articles