#!/usr/bin/env php

<?php
$semaphore_id = 100;
$segment_id   = 200;

// get a handle to the semaphore associated with the shared memory
// segment we want
$sem = sem_get($semaphore_id,1,0600);

// ensure exclusive access to the semaphore
$acquired = sem_acquire( $sem );
if ( ! $acquired ) {
	throw new RuntimeException( 'Cannot acquire semaphore' );
}

// get a handle to our shared memory segment
$shm = shm_attach($segment_id,16384,0600);

// retrieve a value from the shared memory segment
$processes = shm_get_var($shm, 23);

// we were called
$processes['composer'] = $argv;

// move the fake wpcept in the vendor/bin folder
copy(__DIR__ . '/wpcept', getcwd() . '/vendor/bin/wpcept');

// store the value back in the shared memory segment
shm_put_var($shm,23,$processes);

// release the handle to the shared memory segment
shm_detach($shm);

// release the semaphore so other processes can acquire it
sem_release($sem);
