Skip to content

Commit

Permalink
Re-use parser process to improve split performance
Browse files Browse the repository at this point in the history
  • Loading branch information
daohoangson committed Sep 21, 2023
1 parent 9dfb62e commit d0f9238
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions transformers/osm/split.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function main()
if ($parserCliPath === false) {
throw new RuntimeException('parser dir not found');
}
$parserProcess = proc_open($parserCliPath, [0 => ['pipe', 'r'], 1 => ['pipe', 'w']], $parserPipes);
if (!is_resource($parserProcess)) {
throw new RuntimeException('parser could not be started');
}

$workingWrittenPaths = [];
if (file_exists($workingFilePath)) {
Expand Down Expand Up @@ -75,11 +79,8 @@ function main()
continue;
}

$response = json_decode(exec(sprintf(
'%s %s',
$parserCliPath,
escapeshellarg($fullName)
)), true);
fwrite($parserPipes[0], "$fullName\n");
$response = json_decode(trim(fgets($parserPipes[1])), true);
$output = $response['output'];
if (count($output) == $item['level']) {
$jsonFullPath = writeJson($outDir, $item, $output);
Expand All @@ -98,6 +99,7 @@ function main()
}

statisticsPrint($outDir);
proc_close($parserProcess);
}

function getFullName($item): string
Expand Down

0 comments on commit d0f9238

Please sign in to comment.