linuxfront-v2-logistics/thread.php

A lightweight PHP CLI script that accepts a base64-encoded JSON payload, forwards it via HTTP POST to the start_quote.php endpoint (with threading enabled), and prints the response. It’s designed to be invoked (or recursively called) for parallel rate retrieval tasks.

🔍 Overview

This script:

  • Decodes a base64 JSON string from the command-line.
  • Builds an HTTP context for a POST request.
  • Sends the payload to https://www.techlogistics.com/start_quote.php?thread=y.
  • Prints the endpoint’s response and exits.

🛠️ Purpose

  • Offload rate-quoting operations to separate processes.
  • Enable concurrent carrier rate lookups using multiple invocations.
  • Keep the main application responsive while backend requests run in parallel.

📥 Input Handling

// Decode base64-encoded JSON from CLI
$postdata = json_decode(
    base64_decode($argv[1]),
    true
);
  • $argv[1]: Base64-encoded JSON string containing the request method and data.
  • json_decode(…, true) returns an associative array in $postdata.
Argument Position Description
$argv[1] Base64-encoded JSON payload for the POST body.

⚙️ HTTP Request Execution

  1. Prepare the HTTP context options:
    $options = [
      'http' => [
        'header'  => "Content-type: application/json\r\n",
        'method'  => 'POST',
        'content' => $postdata,
      ],
    ];
    
  2. Create a stream context and perform the request:
    $context = stream_context_create($options);
    print_r(
      file_get_contents(
        'https://www.techlogistics.com/start_quote.php?thread=y',
        false,
        $context
      )
    );
    exit;
    
  • stream_context_create builds the context with headers and body.
  • file_get_contents issues the HTTP POST and returns the response.
Option Key Example Value Purpose
header Content-type: application/json Informs server of JSON payload.
method POST Uses HTTP POST.
content Decoded PHP array (JSON-encoded body) The actual request payload.

Note: In strict PHP, content expects a string. If you pass an array, PHP will cast it to "Array". Ensure you json_encode($postdata) when building real payloads.

🧵 Thread Spawning (Commented)

A large commented block demonstrates how the script can be recursively invoked for each carrier:

/* 
$carriers = [98,52,54];
foreach ($carriers as $id) {
  // Build a carrier-specific JSON payload
  $argv = json_encode([
    'method' => 'getRates',
    'data'   => [
      /* …customer details… */,
      'carrier_id' => $id
    ]
  ]);

  echo "Carrier: {$id}\n";
  exec(
    "{$php_path} /path/to/thread.php "
    . base64_encode($argv),
    $output,
    $return_var
  );
  print_r($output);
}
*/
  • exec() calls this script in parallel for each carrier.
  • base64_encode($argv) ensures safe transport via CLI.

⚠️ Debugging

if (false) {
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
}
  • Toggling the if(false) to if(true) enables verbose error output for troubleshooting.
  • start_quote.php (on techlogistics.com): the endpoint that processes quoted rates.
  • PHP CLI: this script runs in a shell environment.
  • Network access: outbound HTTPS to www.techlogistics.com.

💡 Usage Example

PAYLOAD='{"method":"getRates","data":{"customer_id":7,"carrier_id":98,...}}'
ENCODED=$(echo -n "$PAYLOAD" | base64 -w0)
php thread.php "$ENCODED"

This script is key for orchestrating parallel rate-fetching operations in the LinuxFront V2 logistics portal.