0

I use the following code to send a get request to boilerpipe java web api to extract the html contents into plain text of a website,i use telerivet webhook api to send and recieve messages to my server where the php file is located,the timeout provided is 10 sec,i get timeout always with this code,please help me out

if ($_POST['secret'] !== $webhook_secret)
{
    header('HTTP/1.1 403 Forbidden');
    echo "Invalid webhook secret";
}
else 
{
    if ($_POST['event'] == 'incoming_message')
    {
        $content = $_POST['content'];
        $from_number = $_POST['from_number'];
        $phone_id = $_POST['phone_id'];

        // do something with the message, e.g. send an autoreply            
        header("Content-Type: application/json");

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, 
        'http://boilerpipe-web.appspot.com/extract?url=http://www.kvgengg.com&extractor=DefaultExtractor&output=text&extractImages='
        ));
        $content = curl_exec($ch);
        echo $content;

    }
}
1
  • 1
    This looks incorrect... url=http://www.kvgengg.com&extractor=DefaultExtractor If all of that and what follows is the URL, it would need to be encoded. If extractor= is a different parameter in the same URL, you should encode the http://ww.kvgengg.com. Still that may have nothing todo with your timeout. Commented May 25, 2015 at 14:24

1 Answer 1

1

It seems that there is a syntax error as you have an extra parentheses in the url, I've removed it.

As well if you use http_build_query to pass in your parameter it should solve your problem

if ($_POST['secret'] !== $webhook_secret)
{
    header('HTTP/1.1 403 Forbidden');
    echo "Invalid webhook secret";
}
else 
{
    if ($_POST['event'] == 'incoming_message')
    {
        $content = $_POST['content'];
        $from_number = $_POST['from_number'];
        $phone_id = $_POST['phone_id'];

        // do something with the message, e.g. send an autoreply            
        header("Content-Type: application/json");

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, 
            'http://boilerpipe-web.appspot.com/extract?' . 
            http_build_query(array(
                'url' => 'http://www.kvgengg.com',
                'extractor' => 'DefaultExtractor'
                'output' => 'text',
                'extractImages' => ''
            ))
        );
        $content = curl_exec($ch);
        echo $content;

    }
}
Sign up to request clarification or add additional context in comments.

10 Comments

Brother Augwa,It Still Gives Me A TimeOut..Please have a look at this image of my test session postimg.org/image/xogn9axa3 What I Actually Need is to send the Contents Of Variable $content as sms back to telerivet client ...Am I Missing Anything Here?It Works Fine For Static Replies,With The Following Code...header("Content-Type: application/json"); echo json_encode(array( 'messages' => array( array('content' => "This is a static message!")
try outputting the curl url and opening it in your browser. I suspect the url you are using is incorrect, or the remote web service doesn't respond in a suitable amount of time.
I went to kvgengg.com and that website is extremely slow, so that's likely the source of the problem.
it seems the telerviet times out after 10 seconds.
Yes brother, the curl part works pretty well within the browser, is the implementation I used here will do my desired task(sending the curl output to user)? When I contacted telerivet team with this issue, they said to implement using asynchronous task, any idea?
|