1

I'm downloading (video) file attachments using the OneNote REST API with PHP and cURL. While all goes smoothly with files < 30.0 MB, anything larger produces a 502 Bad Gateway error and no data.

Whereas, in a different situation (shared notebook) with a 502 error the addition of "FavorDataRecency: true" to the API request solved the problem, in this situation it has no effect.

What's the way around (or through) this problem?

[EDIT]

It is a timeout problem (thanks Jim). My logs show that file downloads halt with the 502 error exactly at 120 seconds.

My PHP script is running on localhost under IIS 10 on Windows 10. I thought I was onto something when I found the connection timeout for IIS was 120 seconds. But I've upped it to 240 seconds and the timeout barrier is still there.

Other config changes I've made:

  • Upped the FastCgi requestTimeout and activityTimeout in IIS 10.
  • Added a CURLOPT_TIMEOUT of 240 secs (as well as the CURLOPT_CONNECTTIMEOUT of 240 secs already set).

Is there some other timeout setting I'm missing?

Any chance it could be a timeout on the OneNote servers?

Velojet
  • 878
  • 11
  • 18

1 Answers1

1

Sounds like you are hitting a timeout somewhere along the way. PHP has a maximum execution time ini configuration, cURL has timeout settings, and various web servers can have a maximum connection time, this post is similar: "Bad Gateway Error 502" when trying to download server-generated .zip file

It will depend on what software stack you are running but check the configuration settings for timeout values that you are likely exceeding by downloading large files. This is also a good resource for PHP, apache, and FCGI/FastCGI timeouts: https://www.devside.net/wamp-server/apache-and-php-limits-and-timeouts

Community
  • 1
  • 1
Jim
  • 3,210
  • 2
  • 17
  • 23
  • Thanks for coming back promptly with helpful suggestions, Jim. I already had disabled timeout on my PHP script: `ini_set('MAX_EXECUTION_TIME', -1);` and upped the cURL call timeout to 10 mins: `CURLOPT_CONNECTTIMEOUT => 600` without any effect. But I'll explore server options as well. – Velojet Jul 13 '16 at 07:43
  • Yes, it's definitely hitting a timeout of 120 seconds somewhere along the way (thanks again for pointing me in this direction, Jim). I've edited my question to add what further steps I've now taken and what info I've gleaned. – Velojet Jul 15 '16 at 03:08
  • While I doubt it has anything to do with Microsoft's API being down, it is possible they are trying to do something else with the file beforehand (virus scan?). Take a look at your network status and see if it is downloading a large amount of data. If not, it is likely their service hung up while trying to do something with a large file. If so then will need to continue the hunt for a timeout. – Jim Jul 15 '16 at 15:22