本文主要是介绍Strace 追踪 php 模拟页面执行,打印log,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.strace可以追踪某个程序,如果是一个执行文件,是可以用strace进行追踪
strace /usr/local/php/bin/php test.php
但是我们的系统,是用浏览器登录访问,也就是说有request,然后我们的系统进行初始化,然后才能执行,不然会报错
strace -t -f -o strace.txt /usr/local/php/bin/php backend/web/index.php >> 22.thml
这个是要报错的
因此我们需要加入这些参数 HTTP_HOST REQUEST_URI 然后再加入strace就可以了
HTTP_HOST=10.10.10.252:600 REQUEST_URI=/ strace -t -f -o strace.txt /usr/local/php/bin/php backend/web/index.php >> 22.thml
然后就可以在strace.txt查看所有的日志,22.html是这个index.php生成的html代码。
strace是蛮好用的,譬如我想看看我的系统加载的config文件,我的配置都是放到了config文件夹下面
HTTP_HOST=10.10.10.252:600 REQUEST_URI=/ strace -t -f -s 600 /usr/local/php/bin/php backend/web/index.php 2>&1 | grep /config
直接就可以输出出来所有的配置文件:
我的日志:
[root@grande erp]# HTTP_HOST=10.10.10.252:600 REQUEST_URI=/ strace -t -f -s 600 /usr/local/php/bin/php backend/web/index.php 2>&1 | grep /config
11:37:31 read(3, "<?php\n//echo md5(md5('grandbest!c').'admin');\n//exit;\ndefined('YII_DEBUG') or define('YII_DEBUG', true);\ndefined('YII_ENV') or define('YII_ENV', 'dev'); // prod(YII_ENV_PROD=true) , dev(YII_ENV_DEV=true) , test(YII_ENV_TEST=true)\n//global\n\n$active_menu = \"\";\nrequire(__DIR__ . '/../../common/Func.php');\nrequire(__DIR__ . '/../../vendor/autoload.php');\nrequire(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');\nrequire(__DIR__ . '/../../common/config/bootstrap.php');\n\n$config = yii\\helpers\\ArrayHelper::merge(\n require(__DIR__ . '/../../common/config/main.php'),\n require(__DIR__ . '/../../co"..., 4096) = 857
11:37:31 lstat("/www/web/develop/erp/backend/web/../../common/config/bootstrap.php", {st_mode=S_IFREG|0777, st_size=659, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/web/../../common/config", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/bootstrap.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/web/../../common/config/main.php", {st_mode=S_IFREG|0777, st_size=1283, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/main.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/web/../../common/config/main-local.php", {st_mode=S_IFREG|0777, st_size=1321, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/main-local.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/web/../config/main.php", {st_mode=S_IFREG|0777, st_size=3175, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/web/../config", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
11:37:31 open("/www/web/develop/erp/backend/config/main.php", O_RDONLY) = 3
11:37:31 open("/www/web/develop/erp/backend/config/../../common/config/custom", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/blog.php", {st_mode=S_IFREG|0744, st_size=27, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/blog.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/cache.php", {st_mode=S_IFREG|0744, st_size=1089, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/cache.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/category.php", {st_mode=S_IFREG|0744, st_size=165, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/category.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/cookie.php", {st_mode=S_IFREG|0744, st_size=158, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/cookie.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/country.php", {st_mode=S_IFREG|0744, st_size=58, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/country.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/currency.php", {st_mode=S_IFREG|0744, st_size=658, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/currency.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/customer.php", {st_mode=S_IFREG|0744, st_size=521, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/customer.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/email.php", {st_mode=S_IFREG|0744, st_size=806, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/email.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/home.php", {st_mode=S_IFREG|0744, st_size=134, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/home.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/payment.php", {st_mode=S_IFREG|0744, st_size=1647, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/payment.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/product.php", {st_mode=S_IFREG|0744, st_size=4286, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/product.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/shipping.php", {st_mode=S_IFREG|0744, st_size=297, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/shipping.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/store.php", {st_mode=S_IFREG|0744, st_size=749, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/store.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/custom/url.php", {st_mode=S_IFREG|0744, st_size=423, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/custom/url.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/params.php", {st_mode=S_IFREG|0777, st_size=61, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/params.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../common/config/params-local.php", {st_mode=S_IFREG|0777, st_size=161, ...}) = 0
11:37:31 open("/www/web/develop/erp/common/config/params-local.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/params.php", {st_mode=S_IFREG|0777, st_size=460, ...}) = 0
11:37:31 open("/www/web/develop/erp/backend/config/params.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/params-local.php", {st_mode=S_IFREG|0777, st_size=18, ...}) = 0
11:37:31 open("/www/web/develop/erp/backend/config/params-local.php", O_RDONLY) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/menu.php", {st_mode=S_IFREG|0777, st_size=11502, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/local.php", {st_mode=S_IFREG|0777, st_size=797, ...}) = 0
11:37:31 open("/www/web/develop/erp/backend/config/../../myapp/etc/mongo", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/admin_user.php", {st_mode=S_IFREG|0777, st_size=295, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/base_catalog_category.php", {st_mode=S_IFREG|0744, st_size=505, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/base_catalog_category_product.php", {st_mode=S_IFREG|0744, st_size=328, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/base_catalog_product.php", {st_mode=S_IFREG|0744, st_size=764, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/ids.php", {st_mode=S_IFREG|0744, st_size=352, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/order_email.php", {st_mode=S_IFREG|0777, st_size=1171, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/sync_from_onfancy_log.php", {st_mode=S_IFREG|0744, st_size=355, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/web_catalog_category.php", {st_mode=S_IFREG|0744, st_size=2208, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/web_catalog_category_product.php", {st_mode=S_IFREG|0744, st_size=1302, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/web_catalog_product.php", {st_mode=S_IFREG|0744, st_size=2641, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/web_category_link_base_category.php", {st_mode=S_IFREG|0744, st_size=397, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/web_site_body.php", {st_mode=S_IFREG|0744, st_size=272, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/mongo/web_site_update_log.php", {st_mode=S_IFREG|0744, st_size=384, ...}) = 0
11:37:31 open("/www/web/develop/erp/backend/config/../../myapp/etc/modules", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Ebay_Ebayorder.php", {st_mode=S_IFREG|0666, st_size=117, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_Adminlogin.php", {st_mode=S_IFREG|0777, st_size=110, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_Customer.php", {st_mode=S_IFREG|0777, st_size=106, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_Dashboard.php", {st_mode=S_IFREG|0777, st_size=108, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_Erpproduct.php", {st_mode=S_IFREG|0744, st_size=132, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_Product.php", {st_mode=S_IFREG|0777, st_size=104, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_Purchase.php", {st_mode=S_IFREG|0777, st_size=106, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_Resource.php", {st_mode=S_IFREG|0777, st_size=106, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_Sales.php", {st_mode=S_IFREG|0777, st_size=100, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_System.php", {st_mode=S_IFREG|0777, st_size=102, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_User.php", {st_mode=S_IFREG|0744, st_size=98, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_Wish.php", {st_mode=S_IFREG|0777, st_size=106, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Erp_Xxapi.php", {st_mode=S_IFREG|0777, st_size=100, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/config/../../myapp/etc/modules/Wish_Wishorder.php", {st_mode=S_IFREG|0777, st_size=117, ...}) = 0
11:37:31 lstat("/www/web/develop/erp/backend/web/../config/main-local.php", {st_mode=S_IFREG|0777, st_size=757, ...}) = 0
11:37:31 open("/www/web/develop/erp/backend/config/main-local.php", O_RDONLY) = 3
11:37:32 access("/www/web/develop/erp/myapp/code/core/Erp/Adminlogin/etc/config.php", F_OK) = -1 ENOENT (No such file or directory)
这篇关于Strace 追踪 php 模拟页面执行,打印log的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!