You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Plivo PHP API 4.0问题:无法获取通话状态/时长,Action URL未执行?

Troubleshooting Plivo PHP SDK 4.0: Missing Call Status/Details for Billing

Hey Juan, let’s walk through this issue step by step—getting those call details (status, duration, timestamps) is critical for your billing workflow, so let’s figure out why your Action URL isn’t delivering the goods (or why you’re not receiving it properly).

1. First: Confirm Your Action URL is Correctly Set in the API Call

Double-check that you’re passing the action_url parameter properly when initiating the call with SDK 4.0. It’s easy to overlook this, or accidentally use the wrong parameter name. Here’s a quick example of how your call initiation code should look:

use Plivo\RestClient;

$client = new RestClient("YOUR_AUTH_ID", "YOUR_AUTH_TOKEN");
$call = $client->calls->create(
    "+14151234567", // Your Plivo from number
    ["+15557654321"], // Customer's phone number
    "https://your-server.com/answer.php", // Answer URL (handles initial call setup)
    [
        "action_url" => "https://your-server.com/callback.php", // **This is the key for call details**
        "method" => "POST" // Plivo recommends POST for payload-heavy callbacks
    ]
);

Important notes here:

  • Your action_url must be publicly accessible (no localhost—use a tool like ngrok to expose local dev servers if needed)
  • Use HTTPS if possible (Plivo prefers it, though HTTP works for testing)

2. Make Sure Your Callback Endpoint is Ready to Receive Plivo’s Data

Plivo sends call details via a POST request to your Action URL, so your endpoint needs to capture, parse, and respond correctly. Here’s a minimal working example for callback.php:

// Capture Plivo's POST payload
$postData = file_get_contents("php://input");
$callDetails = json_decode($postData, true);

// Log everything first—this is your debugging lifeline
file_put_contents("plivo_call_logs.txt", print_r($callDetails, true) . PHP_EOL, FILE_APPEND);

// Check for the critical billing fields
if (isset($callDetails['status'], $callDetails['duration'], $callDetails['start_time'], $callDetails['end_time'])) {
    // Do your billing logic here: save to DB, calculate charges, etc.
    echo "Callback processed successfully";
} else {
    // Log missing fields to troubleshoot
    error_log("Plivo callback missing required fields: " . print_r($callDetails, true));
    echo "Missing required call details";
}

// Always return a 200 OK response—Plivo needs this to confirm receipt
http_response_code(200);

Plivo will retry callbacks if it gets non-200 responses, but eventually stop if failures persist. So returning a 200 is non-negotiable.

3. Watch Out for Dial XML Action Overrides

If your Answer URL returns a <Dial> XML element (to connect the customer to your chosen agent), the action attribute on that <Dial> tag will override the action_url from your initial API call. That’s a super common gotcha!

Example of what to check in your answer.php:

header("Content-Type: application/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial action="https://your-server.com/callback.php" method="POST">
        <Number>+15559876543</Number> <!-- Agent's number -->
    </Dial>
</Response>';

If you have this <Dial> action set, make sure it points to the same (or correct) callback endpoint you want to use for billing details.

4. Use Plivo’s Dashboard Logs to Debug Directly

This is the fastest way to confirm if Plivo is even hitting your Action URL. Log into your Plivo dashboard, go to Logs > Call Logs, find the problematic call, and click into it. Look for the Callback Logs tab—here you’ll see:

  • Whether Plivo attempted to send the callback
  • The HTTP status code it received from your server
  • The full payload it sent
  • Any error messages if the request failed

If you see "Failed" entries here, you’ll know exactly where the issue is (e.g., 404 means your URL is wrong, 500 means server error in your callback code).

5. Test Your Callback Endpoint Manually

Use curl to simulate a Plivo callback request—this will help you rule out server-side issues without waiting for actual calls. Here’s a sample curl command:

curl -X POST https://your-server.com/callback.php \
  -H "Content-Type: application/json" \
  -d '{
    "call_uuid": "abc-123-def-456",
    "status": "completed",
    "start_time": "2024-05-20T14:30:00Z",
    "end_time": "2024-05-20T14:35:00Z",
    "duration": "300",
    "from_number": "+14151234567",
    "to_number": "+15557654321"
  }'

After running this, check your log file (plivo_call_logs.txt) to see if the data was captured. If it is, your endpoint works—so the issue is likely with Plivo reaching it (firewall, URL accessibility) or your initial call setup.

6. Check Firewall/Server Restrictions

Make sure your server’s firewall isn’t blocking incoming requests from Plivo’s IP ranges. Plivo publishes a list of IPs they use for callbacks—whitelisting these will ensure their requests get through without being blocked.


Once you work through these steps, you should be able to pinpoint whether the Action URL is firing, and fix the issue. If you find specific errors in the logs or get stuck on a particular part of the code, feel free to share more details and I’ll help you dig deeper!

内容的提问来源于stack exchange,提问作者Juan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:48:46