linuxfront-v2-logistics/ajax.php

A lightweight PHP CLI script to fetch and display shipping rates for multiple carriers by delegating HTTP requests to a background thread handler.

⚙️ Configuration

Defines the path to the PHP CLI binary used for executing the thread script.

<?php
$php_path = '/usr/bin/php';

This ensures that subsequent exec() calls invoke the correct PHP interpreter .

🔄 Iteration Control

An outer for loop runs exactly one iteration. This appears to be a placeholder for potential future expansions.

for ($i = 0; $i < 1; $i++) { … }

Inside, a list of carrier IDs is defined for which rates will be fetched .

📦 Carrier List

The script targets a predefined set of carriers:

Carrier IDs
54
98
29
212
108
6
114
64

This array drives the per-carrier payload generation .

📝 Payload Construction

For each carrier, a JSON payload is constructed in the $argv variable. It specifies:

  • method: "getRates"
  • data: Shipment and customer details
  • carrier_id: Current carrier in loop
  • service_level, volume, density, etc.
$argv = '{"method":"getRates","data":{"customer_id":"7","rated_shipment_id":1460738,"bol_no":"DEMO1460738","carrier_id":"'.$val.'",…}}';

This string is later base64-encoded and passed to the thread handler .

🚀 Executing the Thread Handler

The script offloads the actual HTTP request to thread.php by invoking it via the PHP CLI. The $argv payload is encoded to ensure safe transmission.

exec(
    " $php_path /var/www/tech-portals/linuxfront-v2-logistics/thread.php "
    . base64_encode(json_encode($argv)),
    $output,
    $return_var
);
  • $output: Captures CLI output as an array of lines
  • $return_var: Exit status of the thread script

🖨 Output and Termination

Before executing the thread, the script prints the current carrier:

echo 'Carrier: '.$val.'<br>';

After execution, it formats and prints the raw response:

echo '<pre>';
print_r($output);
exit;

An immediate exit ensures the script stops after processing the first carrier in each run .


🔗 Dependency: thread.php

ajax.php relies on thread.php to perform the actual HTTP POST to an external API endpoint. A typical snippet from thread.php:

<?php
$postdata = json_decode(base64_decode($argv[1]), true);
$url      = 'https://www.techlogistics.com/start_quote.php?thread=y';
$options  = [
  'http' => [
    'header'  => "Content-type: application/json\r\n",
    'method'  => 'POST',
    'content' => $postdata,
  ],
];

This handler decodes the payload, sets up the HTTP context, and sends the request to the rate-quoting service .


✔️ Key Responsibilities

  • Configuration: Locates the PHP CLI binary.
  • Carrier Iteration: Loops through a static list of carriers.
  • Payload Assembly: Embeds shipment and customer details into a JSON payload.
  • Delegation: Offloads network I/O to thread.php.
  • Output: Displays carrier identifiers and raw responses for debugging or display.

  • thread.php: Executes HTTP POSTs to start_quote.php with JSON payloads.
  • start_quote.php: (External) Endpoint that processes "getRates" requests.

🚀 Usage

Run from the command line or via a web-facing endpoint to quickly test or benchmark rate generation across multiple carriers.

php ajax.php

Note:
The current script exits after the first carrier due to the exit inside the loop. Removing or relocating this may allow processing all carriers in one invocation.