tags:

views:

104

answers:

2

Hello all,

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: http://stackoverflow.com/questions/669178/does-this-regex-in-php-actually-work

A: 

I've never heard of regexps breaking while switching PHP configs, so I'm wondering if it's the python that might be breaking. This might be a silly question, but have you checked that your exec line works from a terminal?

Adam Benzan
Thats a good quesion and it was the first thing. I did. This exec works and it downloads the file. It just doesn't add the progress to the text file. I can not figure out why. The file is created and is owned by apache user but its empty.
Abs
what's the python versions on old and new server?
ax
Old = Python 2.4.3 (#1, Nov 2 2008, 06:55:35) and New = Python 2.4.3 (#1, May 24 2008, 13:57:05). The python script executes fine and there is output from that command. Its just that there is no match being made from Preg_match
Abs
+1  A: 

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

if( ini_get('safe_mode') ){ print "safe mode on\n"; }else{ print "safe mode off\n"; }

Nate
There is output for both. The first line I show is what it looks like from the command. The second output in the update section is from the PHP output in the browser where I just echo out $progress. Also safe mode is not on, I have checked this.
Abs