Here is proof that my site is not portable. I had some regex that worked perfectly on my old server. I have now transferred my site to a new server and it doesn’t work.
$handle = popen('/usr/bin/python '.YOUTUBEDL.'youtube-dl.py -o '.VIDEOPATH.$fileName.'.flv '.$url.' 2>&1', 'rb'); while(!feof($handle)) { $progress = fread($handle, 8192); $pattern = '/(?<percent>[0-9]{1,3}\.[0-9]{1,2})% of (?<filesize>.+) at/'; ///######Does not execute this if - no matches if(preg_match_all($pattern, $progress, $matches)){ fwrite($fh, $matches[0][0].'\r\n'); } }
The output of the from the shell is something like this and the regex should match filesize and percentage.
[download] 56.8% of 4.40M at 142.40k/s ETA 00:13
The regex worked on the previous server but not this one. Why? How can I debug this?
The difference in the servers is that the previous one was Fedora and its now Centos. Also I specified the shell as /bin/bash.
Is there anything in the PHP.ini that could cause a change in this?
Please help.
Update
The output of $progress is this: (just a small sample)
[download] 87.1% of 4.40M at 107.90k/s ETA 00:05 [download] 89.0% of 4.40M at 107.88k/s ETA 00:04 [download] 91.4% of 4.40M at 106.09k/s ETA 00:03 [download] 92.9% of 4.40M at 105.55k/s ETA 00:03
Update 2
Could that regex fail because of extra spacing in the output?
Also would a different shell make a difference??
[SOLVED]
This was solved and it was due to the regex requiring a P – see here for more details: Does this regex in PHP actually work?
Is the output from the working or non working server? It’s possible safe mode is enabled on the second and the script is refusing to execute. Check the Notes section on this page for more information http://us.php.net/popen
To verify, and I do see the comments where you placed the output of the python command, print out the $progress variable in the php script. I’m not sure if the output you supplied is when you ran the python command from cli or got that from the php script itself. But if it’s from the python script outputting that $progress variable will help determine if popen() is really executing that command.
(You should be able to tell if safe mode is enabled by running phpinfo() in your script)
Or you could do this