Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

petervandijck's avatar

How to change max execution time when calling OpenAI API?

I'm developing locally, using Valet. I am calling the openAI API, which tends to take longer than 30 seconds to stream back a complete answer. I am getting consistent timeout errors: ''' Operation timed out after 30069 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.openai.com/v1/chat/completions ''' I tried these two in the script but it still times out after the defaut 30 seconds: ''' // ini_set('max_execution_time', 300); // doesn't work // 300 seconds instead of default 30 seconds // set_time_limit(300); // doesn't work ''' How do I change the timeout on Valet? I am not great at command line so any actual command line commands are appreciated :)

0 likes
1 reply
Flu's avatar

Maybe you can try to edit your PHP.ini? If you are using Herd: Herd->Show PHP.ini -> Open the Ini-File according to your PHP Version for example in TextEdit and then add: max_execution_time = 300

You can test with echoing phpinfo() in your project to see what vars are actually set. However, i think you should get a response earlier then in 30 seconds otherwise there could be another reason for your problem.

Please or to participate in this conversation.