qcachegrind error: Unknown file format. File generated from php xdebug - php

I am attempting to use xdebug to profile an application written in php7.
I've written a script that sets the follow ini settings:
ini_set('xdebug.trace_format',1); // Note: I tried 0 and 2 here as well
ini_set('xdebug.profiler_enable',1);
xdebug_start_trace('/tmp/cachegrind.out');
// RUN CODE HERE
xdebug_stop_trace();
Running the script created the cachegrind files as I would expect:
root#host:/# ls /tmp | grep cachegrind
cachegrind.out.0028fd.xt
cachegrind.out.0072ab.xt
cachegrind.out.009b09.xt
cachegrind.out.025ac3.xt
Here is the first few lines of a cachegrind file so that the format is visible:
Version: 2.4.1
File format: 4
TRACE START [2016-10-28 05:26:57]
2 3784 1 0.242945 2692856
2 3785 0 0.242955 2692800 DI\Container->set 1 /path/public/api/index.php 100
2 3785 1 0.242966 2692800
2 3786 0 0.242973 2692800 spl_autoload_call 0 /path/public/api/index.php 103
3 3787 0 0.242982 2692896 Fuel\Core\Autoloader::load 1 /path/public/api/index.php 103
4 3788 0 0.242990 2692896 strpos 0 /path/fuel/core/classes/autoloader.php 219
However, when I try to open this file in qcachegrind, it fails to open:
The error message reads: "Error loading /path/to/cachegrind/file: Unknown file format
Anyone know what's going on here? I'd like to be able to use a tool like this to profile my application.
I also shelled out $30 to try opening the file in MCG but that app crashes immediately upon opening any of these files.
As a side note, the file is fairly large, but not so large that I'd expect apps to be freaking out:
❯ ls -al /Users/johnpc/repos/cachegrind.out.094ffa.xt
-rw-r--r-- 1 johnpc staff 62744095 Oct 28 02:13 /Users/johnpc/repos/cachegrind.out.094ffa.xt

that file is a trace file not a callgrind file.
i seems you set trace_output_name and profiler_output_name in the ini to the same string or trying to open the wrong file. you need to set the profiling_* variables in the ini.
see: "Profiling PHP Scripts" in the xdebug docs
a sample profiling output looks like this:
version: 1
creator: xdebug 2.1.1rc1
cmd: /Users/foo/bar/test1.php
part: 1
positions: line
events: Time
fl=php:internal
fn=php::microtime
when you get problems because of the file size, you could also try the app from profilingviewer.com

Related

VSCode - XDebug loads then is not loaded

I am trying to use XDebug with PHP and VS Code on Windows. I have successfully installed XDebug because it shows up in the phpinfo() page.
When I attempt to use XDebug on VS Code, I get this error:
DEBUG Checking PHPLS_ALLOW_XDEBUG
DEBUG The xdebug extension is loaded (2.7.1)
DEBUG Process restarting (PHPLS_ALLOW_XDEBUG=internal|2.7.1|0|*|*)
DEBUG Running C:\Users\***\Documents\Applications\php-7.3.4-nts-Win32-VC15-x64\php.exe -n -c C:\Users\***\AppData\Local\Temp\AF9E.tmp c:\Users\***\.vscode\extensions\felixfbecker.php-intellisense-2.3.10\vendor\felixfbecker\language-server\bin\php-language-server.php --tcp=127.0.0.1:50124 --memory-limit=4095M
DEBUG Checking PHPLS_ALLOW_XDEBUG
DEBUG Restarted (64 ms). The xdebug extension is not loaded
[Info - 11:04:12 AM] 1 files total
[Info - 11:04:12 AM] Indexing project for definitions and static references
Parsing file:///c:/xampp/htdocs/blank/blank.php
[Info - 11:04:12 AM] Indexing project for dynamic references
[Info - 11:04:12 AM] 0 Packages
[Info - 11:04:12 AM] All 1 PHP files parsed in 0 seconds. 148 MiB allocated.
I just had this issue too and looking at the configuration that was being provided (in the original example above it's C:\Users\***\AppData\Local\Temp\AF9E.tmp), I found that the zend_extension line had been commented out.
ie. it appears as this in the .tmp file:
;zend_extension=php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll
The semicolon being the commenting character.
A little experimentation showed that it was commenting it out itself based on the filename. I renamed the DLL to totallynotphpdebgr272.dll and set that as the zend_extension in php.ini. After that change it no longer commented that line in the generated .tmp file and I was able to start debugging php successfully in vscode.

PHP can't see any files on a mounted filesystem

I have a new file server (FilServerB) that I have had up and running for a few months. I've been moving all my processing servers over to use FileServerB for their PHP code. I recently found a server (server name is susan) that I had missed, and it was still connecting to the old file server (FileServerA). When I mounted FileServerB on susan, none of the code would run on it anymore. In ssh, when I go to a directory with PHP code in it, and run "php cleanISL.php", it says this:
Fatal error: Unknown: Failed opening required 'cleanISL.php' (include_path='.:/local/online/live/common:/local/online/pear') in Unknown on line 0
If I create a new php file on the local filesystem, it runs just fine. If I try an is_file or is_directory for a file or directory that I know exists on the mounted filesystem, it always returns false. However, I can glob directories, and it shows the files in there just fine.
I've tried changing (and removing completely) my include_path, I've tried going back to the old file server (which works), and then unmounting the old one and mounting the new one the exact same way (still doesn't work), and a few other things. I can't tell if the issue is with PHP, or somehow with the way the server is mounted, or something else. I've made sure SELINUX is disabled. The issue seems to be only affecting PHP, and only when I mount the new FileServerB, and only on this particular server (susan). But I'm baffled at what could be causing it or how to fix it.
Also, I have mounts to other servers (for data/media) on this same server (susan), and those work just fine, ie, PHP can see and read files on those mounts too.
UPDATE 1, strace info
This is the relevant line of the strace on a failed is_dir:
stat64("/online/live/tools/test/fixes/", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
And this is the output of a stat command on the same dir:
File: `/online/live/tools/test/fixes/'
Size: 4096 Blocks: 8 IO Block: 32768 directory
Device: 18h/24d Inode: 11815229588 Links: 3
Access: (0775/drwxrwxr-x) Uid: ( 1004/ UNKNOWN) Gid: ( 1010/ UNKNOWN)
Access: 2016-07-06 07:28:46.606024801 -0600
Modify: 2016-06-24 16:23:42.206547505 -0600
Change: 2016-06-24 16:23:42.206547505 -0600
And this is a namei -m result:
dr-xr-xr-x /
lrwxrwxrwx online -> /mnt/code/online/
dr-xr-xr-x /
drwxr-xr-x mnt
drwxr-xr-x code
drwxr-xr-x online
drwxrwxrwx live
drwxrwxr-x tools
drwxrwxr-x test
drwxrwxr-x fixes

Deploy PHP using cURL in GAE

I just received a great news that full cURL is supported now.
I followed the instruction to replace "runtime:php" with "runtime:php55" in app.yaml and deployed my php code to Google App Engine using Google App Engine Launcher.
The system responsed error as attached:
..deploy response...............
2015-02-27 23:01:52 Running command: "['C:\\python27_x64\\pythonw.exe', '-u', 'C:\\Program Files\\Google\\Cloud SDK\\google-cloud-sdk\\platform\\google_appengine\\appcfg.py', '--no_cookies', u'--email=jihshiun#gmail.com', '--passin', 'update', 'D:\\Documents\\GAE CloudSite\\Hi']"
Usage: appcfg.py [options] update <directory> | [file, ...]
appcfg.py: error: Error parsing D:\Documents\GAE CloudSite\Hi\app.yaml: Unable to assign value 'php55' to attribute 'runtime':
Value 'php55' for runtime does not match expression '^(?:contrib-dart|dart|go|php|python|python27|java|java7|vm|custom)$'
in "D:\Documents\GAE CloudSite\Hi\app.yaml", line 3, column 10.
2015-02-27 23:02:04 (Process exited with code 2)
.......................
I also tried to add a php.ini with extension = "curl.so" in the file, and the deployment failed too with the same response.
Have I missed something?
Please advise.
I've had the same problem.
You have to update the sdk, download the file corresponding to your plataform and instal it.

Why does rename() return false despite moving a file successully to an NFS mounted disk?

I'm getting an Invalid argument warning when moving a file from a local disk to an NFS mounted disk. The file is moved successfully despite the error message:
Warning: rename(/tmp/image.jpg,/mnt/remote.server-disk1/image.jpg): Invalid argument
The mounted disk:
$ df
remote.server:/disk1 917G 269M 871G 1% /mnt/remote.server-disk1
The exported disk on the remote server:
$ cat /etc/exports
/disk1 remote.server(rw,sync,root_squash,secure,crossmnt,anonuid=504,anongid=504)
The file on the local disk before rename():
$ stat /tmp/image.jpg
File: `image.jpg'
Size: 2105 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 33556339 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 501/ apache) Gid: ( 501/ apache)
...
The file on the remote disk after rename():
$ stat /disk1/image.jpg
File: `image.jpg'
Size: 2105 Blocks: 8 IO Block: 4096 regular file
Device: 821h/2081d Inode: 34603214 Links: 1
Access: (0777/-rwxrwxrwx) Uid: ( 501/ apache) Gid: ( 501/ apache)
...
Any ideas?
Thanks
In Unix you can't rename or move between filesystems, Instead you must copy the file from one source location to the destination location, then delete the source. This will explain the error message you're getting. However, it seems unclear as why it still does the move. This could be related to permissions or the NFS mounted disk is locally cached.
Maybe a bit late, but i think the answer is probably because of permissions linked to the target file system.
We had the same issues, and a strace give us the proper diagnostic:
strace php -r "rename('SOURCE_FILE', 'DST_FILE');";
...
chown("SOURCE_FILE", 0, 0) = -1 EINVAL (Invalid argument)
write(2, "PHP Warning: rename(SOURCE_FILE"..., 192PHP Warning: rename(SOURCE_FILE): Invalid argument in Command line code on line 1
) = 192
write(1, "bool(false)\n", 12bool(false)
In our case, the target file system was an NFS with version 4, and idmap was enabled.
Even a simple
chown $(whoami) $DST_FILE
wasn't working.
It's the default behavior (under debian at least) to have idmap enabled with nfs-common utils.
So even if you fix it by using a copy + unlink (which is the best approach by the way), it may still hide an issue in your underlying file system.
(to disable idmap : https://forums.aws.amazon.com/thread.jspa?threadID=235501)
Maybe it's because you doing this with no quotes
rename(/tmp/image.jpg,/mnt/remote.server-disk1/image.jpg);
try adding quotes
rename('/tmp/image.jpg', '/mnt/remote.server-disk1/image.jpg');
I couldn't resolve this, but copy() and then unlink() worked without error.

PHP and Linux IPC sockets (and Dropbox)

I need to get Dropbox's status on linux.
This is done by interacting with Dropbox using a unix socket file as IPC.
Currently, a Python script exists to do this.
I've got this code so far:
echo 'usr='. get_current_user().'<br/>';
$address='/root/.dropbox/iface_socket';
$socket=socket_create(AF_UNIX,SOCK_STREAM,0);
if(!socket_connect($socket,$address))
die('socket_connect '.socket_last_error().': '.socket_strerror(socket_last_error()));
The above works in that it does know what I want to do, but it fails with this error/output:
usr=root
socket_bind 13: Permission denied
It is interesting to note that both PHP and Dropboxd are running under the same user.
Note: I tried using PHP's fsockopen, but failed (something to do with "bad protocol"). Tried it again and this time round it works....till I get the same error below...
Edit: Again, I know running as root is bad, spare it, ok? :)
Edit 2: As I said earlier, PHP, Apache, Dropbox and this socket file are all under user "root", group "root".
However, if I run the socket under stat, I get the following:
[root#cov .dropbox]# stat iface_socket
File: `iface_socket'
Size: 0 Blocks: 0 IO Block: 4096 socket
Device: 7dh/125d Inode: 255754311 Links: 1
Access: (0600/srw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2011-03-06 17:10:08.000000000 -0600
Modify: 2011-03-06 17:10:08.000000000 -0600
Change: 2011-03-06 17:10:08.000000000 -0600
Couldn't it be that all those -0600 is what is causing this issue? Note that if I chmod 0777 iface_socket, only the first line, (Access: (0600/srw-------)), changes; but not the other 3 underneath.
Edit 3: I was wondering, perhaps this topic would be better moved at unix/unix-like? At this point in time, it's not clear who's at fault in this issue.
Edit 4: Just ran the PHP script through strace like this:
strace php -nef /var/www/html/index.php
The relevant lines from output:
socket(PF_FILE, SOCK_STREAM, 0) = 3
fcntl(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
connect(3, {sa_family=AF_FILE, path="/root/.dropbox/iface_socket"...}, 29) = 0
fcntl(3, F_SETFL, O_RDWR) = 0
close(3) = 0
In the rare case that Apache is running under the same user as Dropbox, I would just use the python command-line interface (Debian) /usr/bin/dropbox as you normally would from a terminal.
root#DevServer1:~# dropbox help
Dropbox command-line interface
commands:
Note: use dropbox help <command> to view usage for a specific command.
status get current status of the dropboxd
help provide help
puburl get public url of a file in your dropbox
stop stop dropboxd
running return whether dropbox is running
start start dropboxd
filestatus get current sync status of one or more files
ls list directory contents with current sync status
autostart automatically start dropbox at login
exclude ignores/excludes a directory from syncing
The fronted script can only effectively be used by the user that dropbox is running under. Everybody else should get a "Dropbox isn't running!" output. In your case you should be able to manipulate dropbox how you see fit from within PHP. Personally I run Dropbox as a restricted user other then my superuser. Using groups, you can safely link in folders at will and file permissions will be enforced.
<?php
$output = shell_exec('dropbox status');
echo "<pre>$output</pre>";
Dropbox isn't running!
A viable alternative.
try this instead:
<?php
$output = shell_exec("ps aux | grep '[d]ropbox'");
echo "<pre>$output</pre>";

Categories