|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-03-17 09:04 UTC] tim at timcrider dot com
split hangs for some reason, but doing the same logical process with other functions returns a very quick result.
The problem is that I'm trying to process the mysqlbinlog output and parse it for easier management. The logical process is as follows.
$sys = `mysqlbinlog logfile`;
This part works fine, but when I try:
$lstk = split("\n", $sys);
the script hangs for well over 5 minutes (I kill the script at that time. However this code produces the desired results in less than 2 seconds:
$mybin = "/usr/local/mysql/bin/mysqlbinlog";
$mylogpath = "/var/lib/mysql/";
$dolog = $mylogpath."towely-bin.010";
$tmpfname = tempnam ("/tmp", "mybinlogger");
$fp = fopen($fp, $tmpfname);
fwrite($fp, `$mybin $dolog`);
fclose($fp);
$lstk = file($tmpfname);
unset($tmpfname);
print count($lstk)."\n";
I am using this from the command line version of php 4.3.2 RC1. Here is my php -v:
PHP 4.3.2-RC1 (cli) (built: Mar 14 2003 13:28:33)
Copyright (c) 1997-2003 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies
with the ionCube PHP Accelerator v1.3.3r2, Copyright (c) 2001-2002, by Nick Lindridge
If you need any other information please feel free to contact me at tim@timcrider.com
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 12:00:01 2025 UTC |
I apologize the second script is bogus. Here is the fix: ---[ works.php ]--- #!/bin/php <?php $mybin = "/usr/local/mysql/bin/mysqlbinlog"; $mylogpath = "/var/lib/mysql/"; $dolog = $mylogpath."towely-bin.010"; $lstk = exec("mysqlbinlog $dolog"); print_r($lstk); print count($lstk)."\n"; ?> (towely) phpbug# more test.php #!/bin/php <?php $mybin = "/usr/local/mysql/bin/mysqlbinlog"; $mylogpath = "/var/lib/mysql/"; $dolog = $mylogpath."towely-bin.010"; $tmpfname = tempnam ("/tmp", "mybinlogger"); $fp = fopen($tmpfname, "w"); fwrite($fp, `$mybin $dolog`); fclose($fp); $lstk = file($tmpfname); unset($tmpfname); print count($lstk)."\n"; ?> --[ End works.php ]--- ---[ broken.php ]--- #!/bin/php <?php $mybin = "/usr/local/mysql/bin/mysqlbinlog"; $mylogpath = "/var/lib/mysql/"; $dolog = $mylogpath."towely-bin.010"; $sys = `mysqlbinlog $dolog`; $lstk = split("\n", $sys); print_r($lstk); print count($lstk)."\n"; ?> ---[ End broken.php ]--- Using exec does not give me the output that I need to do this. exec only returns the last line of the output. I'm trying to get all of the output, which has line breaks at the end of every row. I did a dump of this server using 'php -i > php_ini.txt and can be seen here. http://timcrider.com/php_ini.txt If there is anything else you need me to do let me know. TimI apologize again. This is what 'works.php' SHOULD look like: ---[ works.php ]--- #!/bin/php <?php $mybin = "/usr/local/mysql/bin/mysqlbinlog"; $mylogpath = "/var/lib/mysql/"; $dolog = $mylogpath."towely-bin.010"; $tmpfname = tempnam ("/tmp", "mybinlogger"); $fp = fopen($tmpfname, "w"); fwrite($fp, `$mybin $dolog`); fclose($fp); $lstk = file($tmpfname); unset($tmpfname); print count($lstk)."\n"; ?> --[ End works.php ]---Here is a quick size test I did: ---[ size.php ]--- #!/bin/php <?php $mybin = "/usr/local/mysql/bin/mysqlbinlog"; $mylogpath = "/var/lib/mysql/"; $dolog = $mylogpath."towely-bin.010"; $sys = `mysqlbinlog $dolog`; print "Backtick :: ".strlen($sys)."\n"; ob_start(); system("mysqlbinlog $dolog"); $sys = ob_get_contents(); ob_end_clean(); print "System :: ".strlen($sys)."\n"; $sys = exec("mysqlbinlog $dolog", $lstk); print "Exec :: ".strlen($sys)."\n"; print count($lstk)."\n"; ?> ---[ End size.php ]--- Here's the output ---[ Begin Output ]--- (towely) phpbug# ./sizes.php Backtick :: 3120815 System :: 3120815 Exec :: 79 30626 --[ End Output ]--- If there code in particular you'd like me to run, you could email it to me @ tim at timcrider dot com and I'll post the output of those tests here.