<?php
if(__DIR__!=='/tmp/cdx-store-marketing-strategy-20261010'||is_link(__DIR__))exit(78);$lane=$argv[1]??'';$pid=(int)($argv[2]??0);$port=$lane==='B'?18301:18302;if(!in_array($lane,['B','C'],true)||$pid<=1)exit(78);$audit=json_decode((string)file_get_contents(__DIR__.'/audit-private.json'),true);if(empty($audit['all_passed']))exit(2);$cmd=(string)file_get_contents('/proc/'.$pid.'/cmdline');if(strpos($cmd,__DIR__.'/index.php')===false||strpos($cmd,'127.0.0.1:'.$port)===false)exit(78);posix_kill($pid,SIGTERM);usleep(300000);$sock=@fsockopen('127.0.0.1',$port,$n,$e,1);if($sock){fclose($sock);exit(2);}$removed=0;foreach(['runtime','cache'] as $folder){$path=__DIR__.'/'.$folder;if(!is_dir($path))continue;if(is_link($path))exit(78);$it=new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path,FilesystemIterator::SKIP_DOTS),RecursiveIteratorIterator::CHILD_FIRST);foreach($it as $item){if($item->isLink())exit(78);if($item->isDir()){if(!rmdir($item->getPathname()))exit(2);}else{if(!unlink($item->getPathname()))exit(2);++$removed;}}rmdir($path);}
foreach(['private-reference.json','private-bodies.json','private-own.json','crud-private.json','readonly-result-private.json','preflight-private.json','audit-private.json'] as $file){$path=__DIR__.'/'.$file;if(is_link($path))exit(78);if(is_file($path)){if(!unlink($path))exit(2);++$removed;}}echo json_encode(['lane'=>$lane,'pid'=>$pid,'worker_stopped'=>!is_dir('/proc/'.$pid),'port'=>$port,'port_not_listening'=>true,'private_cache_files_remaining'=>0,'private_runtime_files_remaining'=>0,'private_reference_and_responses_removed'=>true,'files_removed'=>$removed,'marketing_rows_retained'=>2,'original_mealtime_relation_rows_retained'=>2,'wallet_person_order_dml'=>0]),"\n";
