<?php
$lane=$argv[1]??'';$mode=$argv[2]??'';if(!in_array($lane,['B','C'],true)||!in_array($mode,['fresh','auth-write','launch','run-write','inspect-write','init-check','resume-b1','retest-write','float-metadata','pin-status','final-write','run-extra','final-extra'],true))exit(78);$pid=$lane==='B'?10001:112175;$root=$lane==='B'?'/tmp/zhct-http-store-mysql.dQTTBP':'/tmp/zhct-dm-poc-20260928.fcpiiN/store';if(strpos(file_get_contents('/proc/'.$pid.'/cmdline'),$root.'/public')===false)throw new RuntimeException('Approved parent drift');$env=[];foreach(explode("\0",file_get_contents('/proc/'.$pid.'/environ')) as $item){$v=explode('=',$item,2);if(count($v)===2)$env[$v[0]]=$v[1];}if(($env['POC_EXTERNAL_STUBS']??'')!=='1'||($env['POC_REAL_QUEUE']??'0')!=='0')throw new RuntimeException('External boundary');$env['PM_LANE']=$lane;$env['PM_ROOT']=$root;$env['NW_STEP']=$argv[3]??'';
$args=[$lane==='B'?'/usr/local/php7.3/bin/php':'/www/server/php/73/bin/php'];if($lane==='C')array_push($args,'-c','/www/server/php/73/etc/php-cli.ini','-d','extension=/home/dmdba/dmdbms/drivers/php_pdo/libphp73_dm.so','-d','extension=/home/dmdba/dmdbms/drivers/php_pdo/php73_pdo_dm.so');array_push($args,'-d','display_errors=0','-d','log_errors=0');
if($mode==='launch'){$port=$lane==='B'?18831:18832;if($socket=@fsockopen('127.0.0.1',$port,$n,$e,1)){fclose($socket);throw new RuntimeException('Port occupied');}if(!is_file(__DIR__.'/private-auth-write.json'))throw new RuntimeException('Auth first');array_push($args,'-S','127.0.0.1:'.$port,'-t',__DIR__,__DIR__.'/index-write.php');$command='nohup '.implode(' ',array_map('escapeshellarg',$args)).' </dev/null >/dev/null 2>&1 & echo $!';}else{array_push($args,__DIR__.'/'.$mode.'.php');$command=implode(' ',array_map('escapeshellarg',$args));}
$process=proc_open($command,[1=>STDOUT,2=>['file',__DIR__.'/private-write-error.log','a']],$pipes,null,$env);exit(proc_close($process));
