Fernando Puente: Gossip the server never hurts #MaratonWP # 10AniversarioAyudaWP

We continue with another fantastic article of #MaratonWP that we will be doing all day today to celebrate 10th Anniversary of WordPress Help . Keep an eye on every hour there will be surprises, with gifts and more WordPress tricks, and do not miss the Twitter hashtag # 10AniversarioAyudaWP .


You have just started a new project, or you inherit one that you do not know anything about , you land on the server and everything looks like a black box that nobody knows about, few dare to ask and, as always, little documentation about it. What less than knowing where we are! Gossip a bit from the server before diving into the code.

Beyond our WordPress environment, we have to stick normally with the platform where it is installed, often chosen by a third party or imposed in advance, so I bring you a small code that has been accompanying me for many years, that has been gaining and losing functions, and that has become my chapter zero of the file functions.php the one of putting nothing else to begin.

And it is that I like to know where I'm staying, like when I go to a hotel and the first thing I do is go through it and make a mental map of where everything is located: on a server, the same.

The code that I bring you next generates a small widget on the WordPress desktop with useful information about the system where our WordPress installation is running: date and time, information about PHP, the operating system or the IP's that the machine uses. [19659011] function add_system_info_function ()
{
    echo '

Datetime

';
    // Server time
    exec ("date '+% d /% m /% Y% H:% M% Z'", $ output, $ return);
    if (! $ return)
    {
        echo 'Server -';
        echo ''. $ output [0]. '';
        echo '
';
    }
    // Default time in PHP executions
    echo 'PHP -';
    echo ''. date ("d / m / Y H: i"). ''. date_default_timezone_get (). '';
    echo '
';
    // Default time for WordPress
    echo 'WordPress -';
    echo ''. date ("d / m / Y H: i", current_time ('timestamp')). ''. get_option ('timezone_string'). '';
    echo '
';
    echo '


';
    echo '

PHP

';
    //Version
    echo 'Version -';
    echo ''. PHP_VERSION '';
    echo '
';
    // Path to PHP
    echo 'Path -';
    echo ''. $ _SERVER [‘PHPHANDLER’]. '';
    echo '
';
    echo '


';
    echo '

System

';
    //OS
    echo 'OS -';
    echo ''. php_uname (). '';
    echo '
';
    // Root of the web
    echo 'DOCUMENT ROOT folder -';
    echo ''. $ _SERVER [‘DOCUMENT_ROOT’]. '';
    echo '
';
    // User running
    exec ("whoami", $ output, $ return);
    if (! $ return)
    {
        echo 'who am i -';
        echo ''. $ output [1]. '';
        echo '
';
    }
    echo '


';
    echo '

Server IP

';
    $ ch = curl_init ();
    curl_setopt ($ ch, CURLOPT_URL, "https://ifconfig.co/json");
    curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true);
    $ result_IP = curl_exec ($ ch);
    curl_close ($ ch);
    $ json = json_decode ($ result_IP, true);
    // server exit IP
    echo 'Output -';
    echo ''. $ json [‘ip’]. '';
    echo '
';
    // server input IP
    echo 'Input -';
    echo ''. $ _SERVER [‘SERVER_ADDR’]. '';
    echo '
';
}
// Add an information widget in the admin part to manage the affiliate url
function add_system_info_widget () {
    if (is_admin ()) {
    // Add widget
    wp_add_dashboard_widget (
                     'add_system_info_widget_slug', // Widget slug.
                     'System info by @fpuenteonline', // Title.
                     'add_system_info_function' // Display function.
                     );
   }
}
add_action ('wp_dashboard_setup', 'add_system_info_widget');

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22 [19659008] 23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47 [19659008] 48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72 [19659008] 73

74

75

76

function add_syst em_info_function ()

{

echo '

Datetime

' ; ]

// Server Time

exec ( "date '+% d /% m /% Y% H: % M% Z '" $ output $ return ) ;

if (! $ return )

{

echo 'Server -' ;

echo '' . $ ] ;

] echo '
'
;

}

// Default time in PHP executions

echo 'PHP -' ;

echo '' . [19659089] date ( "d / m / YH: i" ) . '' . date_default_timezone_get ( ) . '' ;

echo '
'
;

] // Default time for WordPress

echo 'WordPress -' ; [19659008] echo '' . date ( "d / m / YH: i" ] current_time ) ) . . . . ] (

] 'timezone_string' ) . '' ; [19659000] echo '
'
;

echo '


' ;

echo '

PHP

';

// Version

echo ' Version – ';

echo '' . PHP _ VERSION . '' ;

echo '
] '
;

// Path to PHP

echo ' Path – ';

echo '' . $ _SERVER [ 'PHPHANDLER' ] . '' ;

echo '
'
;

echo '


' ;

echo '

System

' ;

// Operating system

echo [19659095] 'OS -' ;

echo '' . php_uname () . '' ;

echo '
'
;

// Root of the web

echo 'DOCUMENT ROOT folder -' ; [19659008] echo '' . $ _SERVER [ 'DOCUMENT_ROOT' ] . '' ;

echo '
'
;

// User running

exec ( "whoami" $ output $ return ) ;

if (! $ return )

{

echo 'who am i -' ;

echo '' . $ ] [

] ] ;

] [19459095] '
'
;

} [19659000] '
' echo '


' ];

echo '

Server IP

' ;

$ ch [19659480] [19659] ; ; ; ; ] ; ; ; , CURLOPT_URL "https://ifconfig.co/json" ) ;

curl_setopt ( $ ch CURLOPT_RETURNTRANSFER true ) ;

$ result_IP = curl_exec ( $ ch ) ;

] curl_close ( $ ch ) ;

$ json = [19659089] json_decode ( $ result_IP true ) ;

// IP server output

echo 'Output -' ;

echo '' ]. $

] json [ 'ip' ] . '' ;

echo '
'
;

// IP server input

echo ] 'Input -' ;

echo '' . $ _SERVER [ 'SERVER_ADDR' ] . '' ;

echo '
'
;

}

// Add an information widget in the in the admin part for management of the affiliate url

function add_system_info_widget () {

if ( is_admin () ) {

// Add widget [19659008] wp_add_dashboard_widget (

'add_system_info_widget_slug' // Widget slug.

'System info by @fpuenteonline' // Title.

'add_system_info_function' // Display function.

) ;

}

}

add_action ( 'wp_dashboard_setup' 'add_system_info_widget' ) ;

I have always found it very useful especially when working on international projects, with different time zones and different machines at the same time, where having something badly synchronized can make us waste time and generate an impact on the project.

To think that sometimes, not only do we execute code inside the WordPress installation, use external services that are called as individual files (which may be in another time) or even services of the machine itself, such as cron, with other time programming than ours.

The information of the system also gives us useful reports with the compatibility of certain packages, as well as the physical location of server folders, which allows us to locate files in an absolute way when sometimes the relative does not work.

Also very useful to know the IP of the output of the machine in which we are working, which is usually not the same as our domain or IP input, especially in shared environments.

I use it for two functions: notify third party services from which IP I will access ( Exit IP of my server) and to secure other external services that I have in other installations (which I only allow access from that IP).

Other functions such as disk space or can inodes of the installation have been lost along the way, since they are used less and less.

So, a widget recommended for all those developers, or just restless gossips, who like me They inherit a project and do not have much information about the system or it is difficult to find with a quick glance.

I hope you enjoy it, and if you feel like it, send me that little info that you also like to gossip about. [19659008] Happy holidays to all and prosperous WP 2018

Fernando Puente

I am a computer scientist by vocation and profession, occasional trainer and beginner of eating and drinking.

I have 21 years of experience in IT, 11 of them in online media and since 2007 with WordPress platforms for own media and third-party projects.

I have extensive experience in managing large multidisciplinary teams, including offshoring and international, from the conceptualization of the project to the exploitation

Twitter: @fpuenteonline

Loading …

May also help you: