@@ -327,11 +327,11 @@ control character (``Ctrl-D`` on Unix systems or ``Ctrl-Z`` on Windows).
327
327
Setting a Timeout for User Input
328
328
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
329
329
330
- .. versionadded :: 7.4
331
-
332
- The timeout functionality for questions was introduced in Symfony 7.4 .
330
+ Sometimes, commands can hang if a user takes too long to respond. For example,
331
+ if interactive questions are used inside an open database transaction, a delayed
332
+ response could leave the transaction open for too long .
333
333
334
- You can set a maximum time limit for user input by using the
334
+ You can prevent this by setting a maximum time limit for input using the
335
335
:method: `Symfony\\ Component\\ Console\\ Question\\ Question::setTimeout ` method.
336
336
If the user doesn't respond within the specified timeout, a
337
337
:class: `Symfony\\ Component\\ Console\\ Exception\\ MissingInputException ` will be thrown::
@@ -346,7 +346,7 @@ If the user doesn't respond within the specified timeout, a
346
346
$helper = new QuestionHelper();
347
347
348
348
$question = new Question('Please enter your answer');
349
- $question->setTimeout(30); // 30 seconds timeout
349
+ $question->setTimeout(30); // 30 seconds
350
350
351
351
try {
352
352
$answer = $helper->ask($input, $output, $question);
@@ -359,15 +359,11 @@ If the user doesn't respond within the specified timeout, a
359
359
return Command::SUCCESS;
360
360
}
361
361
362
- This is particularly useful when you have interactive questions inside database
363
- transactions or other time-sensitive operations where hanging indefinitely
364
- could cause problems.
365
-
366
362
.. note ::
367
363
368
364
The timeout only applies to interactive input streams. For non-interactive
369
- streams (like pipes or files), the timeout setting is ignored and the
370
- question behaves normally.
365
+ streams (such as pipes or files), the timeout is ignored and the question
366
+ behaves normally.
371
367
372
368
You can also use timeouts with other question types such as
373
369
:class: `Symfony\\ Component\\ Console\\ Question\\ ConfirmationQuestion ` and
@@ -377,10 +373,14 @@ You can also use timeouts with other question types such as
377
373
378
374
// ...
379
375
$question = new ConfirmationQuestion('Do you want to continue?', false);
380
- $question->setTimeout(10); // 10 seconds timeout
376
+ $question->setTimeout(10); // 10 seconds
381
377
382
378
$continue = $helper->ask($input, $output, $question);
383
379
380
+ .. versionadded :: 7.4
381
+
382
+ The timeout functionality for questions was introduced in Symfony 7.4.
383
+
384
384
Hiding the User's Response
385
385
~~~~~~~~~~~~~~~~~~~~~~~~~~
386
386
0 commit comments