Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Ads API PHP: Video upload using AdVideo class

Query in PHP using API v2.4

When I try to upload a video using AdVideo class as shown below,

  $time_limit = ini_get('max_execution_time');
  set_time_limit(0);
  $video = new AdVideo(null, $account_id);
  $video->{AdVideoFields::NAME} = *name*;
  $video->{AdVideoFields::SOURCE} = *video_path*;
 try {
     $video->create();
 } catch (\FacebookAds\Http\Exception\RequestException $e) {
     echo "<script>alert('" . $e->getErrorUserMessage() . "')</script>";
     set_time_limit($time_limit);
     return;
 }
 set_time_limit($time_limit);

Result:

I get the following exception -
'Operation timed out after 60000 milliseconds with 0 bytes received'

The video I upload is around 20MB and it would take more time to upload. How to handle this? Is there a way we can show the progress of upload? Does this class support chunked upload ?

Tried set_time_limit(0); but no help.

like image 536
Shanmukharaja Muroor Avatar asked Jun 03 '26 11:06

Shanmukharaja Muroor


1 Answers

This looks like you're hitting the CURL timeout which is 60 by default within the SDK.

You can use the following code to change the timeout to be unlimited:

Api::instance()
  ->getHttpClient()
  ->getAdapter()
  ->getOpts()
  ->offsetSet(CURLOPT_TIMEOUT, 0);
like image 181
Paul Bain Avatar answered Jun 06 '26 01:06

Paul Bain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!