I've been looking into this alot lately because I find it easier to reuse my RRD definitions and whatnot with PHP versus Perl and I never bothered to learn Python. And I feel it should be unnecessary to have apache in the way all the time.
Unfortunately I have no solutions, but I do have some information that might be useful to someone more advanced than me. So far I've only been focusing on rrd_create() if only for the chicken/egg factor. Can't manipulate an RRD that doesn't exist yet now can we? I'm using PHP 5.1.6 and RRDtool 1.3.7 tho I found the same problem with the 1.2.x series as well as PHP4 (32 and 64 bits alike). That problem being that php-rrd functions work as expected when called thru the webserver but seg fault when called from the command line ("/usr/bin/php myscript.php") Running it thru GDB I have determined that when rrd_parsetime() is called from rrd_create() the first arg (const char *tspec) is magically transformed from whatever pointer it was to 0x0! The second arg makes it thru completely unharmed (rrd_time_value_t * ptv). My GDB output: 67 if ((parsetime_error = rrd_parsetime(optarg, &last_up_tv))) { (gdb) p opt $1 = 98 (gdb) p optarg $2 = 0xf9ded28 "1247798125" (gdb) p last_up_tv $3 = {type = 48, offset = 262008040, tm = {tm_sec = 262004736, tm_min = 0, tm_hour = 3, tm_mday = 0, tm_mon = 1944558168, tm_year = 32767, tm_wday = -1215872982, tm_yday = 51, tm_isdst = 24, tm_gmtoff = 24, tm_zone = 0xf9dece8 "RRA:AVERAGE:0.5:288:797"}} (gdb) p &last_up_tv $4 = (rrd_time_value_t *) 0x7fff73e79600 (gdb) s rrd_parsetime (tspec=0x0, ptv=0x7fff73e79600) at rrd_parsetime.c:842 842 { (gdb) bt #0 rrd_parsetime (tspec=0x0, ptv=0x7fff73e79600) at rrd_parsetime.c:842 #1 0x00000031d4207737 in rrd_create (argc=11, argv=0xf9debb0) at rrd_create.c:67 #2 0x00002b583a62d5a6 in zif_rrd_create (ht=3, return_value=0xf9deb68, return_value_ptr=0x0, this_ptr=0x0, return_value_used=0) at /home/frank/src/phprrdtool-mine/rrdtool.c:161 #3 0x00000000005a56bf in ?? () #4 0x0000000000595ccc in execute () #5 0x0000000000579d48 in zend_execute_scripts () #6 0x00000000005404fa in php_execute_script () #7 0x00000000005f32c8 in main () Prior to calling rrd_parsetime(), optarg is clearly a pointer to a string containing a valid unix timestamp, as expected. But as the backtrace shows, it is passed to rrd_parsetime() as 0x0 (NULL). For the life of me I can't figure out why. Obviously the rrdtool executable takes the same code path but does not exhibit the same behavior. I guess my next step will be to run it thru DDD and watch the registers and whatnot as I step thru the CPU instructions one by one and hopefully that will show me where it goes wrong. But it's been about 14 years since I've dug down to that level so I'm not expecting any miracles. I hope this information is useful to someone who might have a better understanding as to why a function parameter would vanish like that between the time the function was called and when it was entered but only with the php cli. -Frank admin-14 wrote: > > Hello, > > I got strange problem. I hope you might help me. > > There is a script which works very properly from browser. No errors > and files are generated ok. But when I run this script from command > line I got segmentation fault. All permissions are ok. What can be the > problem? > > RRDtool 1.3.8 > > System: > Linux version 2.6.18-128.el5PAE (mockbu...@builder16.centos.org) (gcc > version 4.1.2 20080704 (Red Hat 4.1.2-44)) #1 SMP Wed Jan 21 11:19:46 EST > 2009 > (Centos5+Directadmin) > > PHP: > PHP 5.2.9 (cli) (built: May 11 2009 23:11:30) > Copyright (c) 1997-2009 The PHP Group > Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies > with XCache v1.2.2, Copyright (c) 2005-2007, by mOo > with the ionCube PHP Loader v3.1.34, Copyright (c) 2002-2009, by > ionCube Ltd. > > Perl: > perl-5.8.8-18.el5_3.1 > > > Here is example: > [r...@server public_html]# php con.php > openvz-6130.rrd > Segmentation fault > [r...@server public_html]# > > strace show: > lseek(5, 0, SEEK_SET) = 0 > getdents(5, /* 41 entries */, 4096) = 1148 > stat64("/home/testuser/rrd/traffic/openvz-6130.rrd", > {st_mode=S_IFREG|0777, st_size=71152, ...}) = 0 > access("/home/testuser/rrd/traffic/openvz-6130.rrd", R_OK) = 0 > lstat64("/home/testuser/rrd/traffic/openvz-6130.rrd", > {st_mode=S_IFREG|0777, st_size=71152, ...}) = 0 > write(1, "openvz-6130.rrd\r\n ", 21openvz-6130.rrd > ) = 21 > time(NULL) = 1245184220 > time(NULL) = 1245184220 > time(NULL) = 1245184220 > time(NULL) = 1245184220 > time(NULL) = 1245184220 > time(NULL) = 1245184220 > time(NULL) = 1245184220 > time(NULL) = 1245184220 > stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2679, ...}) = 0 > gettimeofday({1245184220, 320367}, NULL) = 0 > time(NULL) = 1245184220 > time(NULL) = 1245184220 > stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2679, ...}) = 0 > --- SIGSEGV (Segmentation fault) @ 0 (0) --- > +++ killed by SIGSEGV +++ > [r...@server public_html]# > > > > > > > The php script below: > <?php > > $di=new DirectoryIterator("/home/testuser/rrd/traffic/"); > $i= 0; > foreach($di as $file) { > if( !$file -> isDir() && !$file -> isDot() && $file -> > isReadable() && !$file -> isLink() ) > { > $i++; > // if( $i < 3) > // continue; > echo $file -> getFilename( ).' > '; > > $opts = array( > "--title", "Server traffic ".$file -> getFilename( ), > "--start", mktime (0,0,0,date("m") ,date("d"),date("Y")), > "--step", '300', > "--width", "600", > "--height", "480", > "--vertical-label", "kB/s", > "--rigid", > "--color", "BACK#000000", > "--color", "SHADEA#000000", > "--color", "SHADEB#000000", > "--color", "FONT#DDDDDD", > "--color", "CANVAS#202020", > "--color", "GRID#666666", > "--color", "MGRID#AAAAAA", > "--color", "FRAME#202020", > "--color", "ARROW#FFFFFF", > // "HRULE:60000#0000FF:Maximum allowed", > "DEF:in=/home/testuser/rrd/traffic/".$file -> > getFilename( ).":incoming:AVERAGE", > "DEF:out=/home/testuser/rrd/traffic/".$file -> > getFilename( ).":outgoing:AVERAGE", > "DEF:tot=/home/testuser/rrd/traffic/".$file -> > getFilename( ).":total:AVERAGE", > "LINE2:in#0000ff:Incoming Traffic Avg.", > "LINE2:out#00ff00:Outgoing Traffic Avg.", > "LINE2:tot#ff0000:Total Traffic Avg.", > "PRINT:in:AVERAGE:incoming\: %1.2lf b/s", > "PRINT:out:AVERAGE:outgoing\: %1.2lf b/s", > "PRINT:tot:AVERAGE:total\: %1.2lf b/s" > ); > > $ret = > rrd_graph("/home/testuser/domains/testuser.mydomain.com/public_html/_rrd/".$file > -> getFilename( ).".gif", $opts, count($opts)); > > if( !is_array($ret) ) > { > $err = rrd_error(); > > echo "rrd_graph() ERROR: $err\n"; > } > > } > } > > ?>[ > > -- > regards, > Marcin > > _______________________________________________ > rrd-developers mailing list > rrd-developers@lists.oetiker.ch > https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers > > -- View this message in context: http://n2.nabble.com/Segmentation-fault-when-run-from-php-cli.-tp3088833p3270215.html Sent from the RRDtool Developers Mailinglist mailing list archive at Nabble.com. _______________________________________________ rrd-developers mailing list rrd-developers@lists.oetiker.ch https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers