-1

Up until a few days ago, I had this working. It had been working for a long time. I'm not sure if it was because of upgrading PHP 8.0.12 to 8.0.13, or because yt-dlp updated and has changed something since. I have not changed my code.

This works:

passthru($yt_dlp_command);

However, it doesn't let me run my own function while it's executing, which is the whole point.

This does no longer work, but worked up until recently:

ob_start();
$a = popen($yt_dlp_command, 'r');

if ($a)
{
    $response = fgets($a, 10); // I've tried numerous other values than 10 as well.

    if ($response)
    {
        while ($row_data = $response)
        {
            ob_flush();
            flush();
            my_function();
            echo $row_data;
        }
    }

    pclose($a);
}

ob_end_clean();

No matter what options I try for yt-dlp, such as --no-progress or --newline (or combinations of these, or none), it just won't show anything but the first line, or the beginning of the first line repeated endlessly in a broken manner.

If I run the $yt_dlp_command in a cmd.exe, it works perfectly with full animated output and all that.

I'm completely stuck now. No idea what else to try. It's probably yt-dlp that has changed something in how it outputs stuff, but even if that's the case, it's weird to me how certain programs can just break this code. It should work regardless of what specific program is being run.

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
user17535142
  • 71
  • 1
  • 6
  • It is likely impossible for us to give you a useful answer without knowing all or some of the following: 1) What is your $yt_dlp_command (or at least an example of one you have tried) 2) What is my_function() supposed to do? 3) What is the expected behavoir/output of this script? 4) What version of yt-dlp are you using? – Josiah Hudson Dec 06 '21 at 19:30
  • 1. Doesn't matter. 2. It's just an example of a function that's being called while the output is going on. 3. Please read. 4. Latest, always. – user17535142 Dec 06 '21 at 19:34
  • I'm trying to help you here, but the information I am asking for is not unusual, and quite likely contains key information needed to help you figure out your issue. Again: 1) How do you expect us to help you if we cannot even reproduce the input your script is choking on? 2) The contents of this function could very well be modifying state or causing the script to hang. If my_function() makes no material difference to behavior, I suggest commenting it out or removing it from your example. 3) I'm asking what you *want* it to do. 4) Best to explicitly list for posterity. – Josiah Hudson Dec 06 '21 at 19:41
  • @jpheldson The whole point of the code is to run a function at the same time. That's why the call is there. You're not reading, just like everyone these days. It's become virtually impossible to get help due to this. – user17535142 Dec 06 '21 at 19:44
  • in your question you say: "I'm completely stuck now". Getting stuck is often a result of getting focused on the wrong part of a problem. A common technique to getting unstuck is to "take a step back" by substantiating all assumptions involved in a solution. The solution to your problem is likely hidden in those details you deem irrelevant. For example, a common issue that can break a script like this is that operating systems often buffer pipes between processes. This would be difficult to test for without having an example of the yt-dlp command you are running. – Josiah Hudson Dec 06 '21 at 19:52

1 Answers1

0

After playing with your script a bit, I realized that the condition on your while-loop is never updated, so it loops endlessly with the first bit of data returned. At the very least I would recommend adding another fgets() call at the bottom of your while-loop to grab the next bit of data from the forked process call.

Josiah Hudson
  • 1,015
  • 8
  • 14