Skip to content

Commit

Permalink
Requiring PHP7.3+. Implementing hrtime for improved performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
sybrew committed Jul 26, 2022
1 parent afa19ca commit 9a2e431
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 35 deletions.
5 changes: 3 additions & 2 deletions bootstrap/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ function can_load_class() {
*
* @since 1.0.0
* @since 2.5.1 Now handles mixed-case class names.
* @since 2.6.0 Now uses `hrtime()` instead of `microtime()`.
* @uses TSF_EXTENSION_MANAGER_DIR_PATH_CLASS
* @access private
*
Expand Down Expand Up @@ -275,7 +276,7 @@ function _autoload_classes( $class ) {
static $_timenow = true;
// Prevent running two timers at once, restart timing once done loading batch.
if ( $_timenow ) {
$_bootstrap_timer = microtime( true );
$_bootstrap_timer = hrtime( true );
$_timenow = false;
} else {
$_bootstrap_timer = 0;
Expand All @@ -293,7 +294,7 @@ function _autoload_classes( $class ) {
require TSF_EXTENSION_MANAGER_DIR_PATH_CLASS . "{$rel_dir}{$file}.class.php";

if ( $_bootstrap_timer ) {
$_t = microtime( true ) - $_bootstrap_timer;
$_t = ( hrtime( true ) - $_bootstrap_timer ) / 1e9;
\The_SEO_Framework\_bootstrap_timer( $_t );
\TSF_Extension_Manager\_bootstrap_timer( $_t );
$_timenow = true;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php": "~7.2 || ^8.0 || ^8.1",
"php": "~7.3 || ^8.0 || ^8.1",
"composer/installers": "^1.0"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions extensions/essentials/articles/trunk/views/sitemap/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

$tsf = the_seo_framework();

$tsf->the_seo_framework_debug and $timer_start = microtime( true );
$tsf->the_seo_framework_debug and $timer_start = hrtime( true );

$sitemap_bridge = \The_SEO_Framework\Bridges\Sitemap::get_instance();

Expand Down Expand Up @@ -54,7 +54,7 @@ class_alias( '\The_SEO_Framework\Builders\Sitemap', '\The_SEO_Framework\Builders
echo "\n" . '<!-- Site estimated peak usage: ' . number_format( memory_get_peak_usage() / 1024 / 1024, 3 ) . ' MB -->';
echo "\n" . '<!-- System estimated peak usage: ' . number_format( memory_get_peak_usage( true ) / 1024 / 1024, 3 ) . ' MB -->';
echo "\n" . '<!-- Freed memory prior to generation: ' . number_format( $sitemap_bridge->get_freed_memory( true ) / 1024, 3 ) . ' kB -->';
echo "\n" . '<!-- Sitemap generation time: ' . number_format( microtime( true ) - $timer_start, 6 ) . ' seconds -->';
echo "\n" . '<!-- Sitemap generation time: ' . number_format( ( hrtime( true ) - $timer_start ) / 1e9, 6 ) . ' seconds -->';
echo "\n" . '<!-- Sitemap caching enabled: ' . ( $tsf->get_option( 'cache_sitemap' ) ? 'yes' : 'no' ) . ' -->';
echo "\n" . '<!-- Sitemap transient key: ' . esc_html( $this->get_sitemap_transient_name() ) . ' -->';
}
7 changes: 5 additions & 2 deletions extensions/free/amp/trunk/amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function do_output_hook() {

\do_action( 'the_seo_framework_do_before_amp_output' );

$output_start = microtime( true );
$output_start = hrtime( true );

$output = '';

Expand All @@ -129,7 +129,10 @@ public function do_output_hook() {

$output = $tsf->get_plugin_indicator( 'before' )
. $output
. $tsf->get_plugin_indicator( 'after', $output_start );
. $tsf->get_plugin_indicator(
'after',
( $output_start - hrtime( true ) ) / 1e9
);

// phpcs:ignore, WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped.
echo PHP_EOL . $output . PHP_EOL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,24 +322,6 @@ final public function import() {
]
);
} else {
if ( 1984 == $post_id )
yield 'debug' =>
[

[
'transport_value' => $transport_value,
'post_id' => $post_id,
'from_data' => $transmuter['from_data'] ?? null,
'from' => [ $from_table, $from_index ],
'existing_value' => $existing_value,
'has_transmuter_to' => $has_transmuter_to,
'set_value' => $set_value,
],
$actions,
$results,
$cleanup,
];

// $actions and $results are passed by reference.
$this->transmute(
$set_value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct( $id ) {
* @param mixed $data The data to store
*/
public function store( $data ) {
static::$store[ $this->id ][ uniqid( microtime( true ), true ) ] = $data;
static::$store[ $this->id ][ uniqid( hrtime( true ), true ) ] = $data;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions inc/classes/core.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,8 @@ final protected function get_extension_autload_path( $namespace ) {
* @since 1.2.0
* @since 1.3.0 Now handles namespaces instead of class bases.
* @since 2.5.1 Now supports mixed class case.
* @since 2.6.0 Now supports branched path files.
* @since 2.6.0 1. Now supports branched path files.
* 2. Now uses `hrtime()` instead of `microtime()`.
*
* @param string $class The extension classname.
* @return bool False if file hasn't yet been included, otherwise true.
Expand All @@ -1169,7 +1170,7 @@ final protected function autoload_extension_class( $class ) {
static $_timenow = true;

if ( $_timenow ) {
$_bootstrap_timer = microtime( true );
$_bootstrap_timer = hrtime( true );
$_timenow = false;
} else {
$_bootstrap_timer = 0;
Expand Down Expand Up @@ -1200,7 +1201,7 @@ final protected function autoload_extension_class( $class ) {
}

if ( $_bootstrap_timer ) {
$_t = microtime( true ) - $_bootstrap_timer;
$_t = ( hrtime( true ) - $_bootstrap_timer ) / 1e9; // ns to s
\The_SEO_Framework\_bootstrap_timer( $_t );
\TSF_Extension_Manager\_bootstrap_timer( $_t );
$_timenow = true;
Expand Down
7 changes: 3 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ Please refer to [the installation instructions on our website](https://kb.theseo
* TODO Use tsf() insteadof the_seo_framework()
* TODO use API functions of TSF (memo, has_run, isset()?..: et al.)
* TODO refactor coalesce_var to PHP 7.0+.
* TODO Start requiring PHP 7.2+
* Start requiring PHP 7.3+
* We'd love to use 7.3+ but 4.2% of our users are on 7.2 or lower (measured 2022/07/10).
* Otto said we'd have to learn from <https://wordpress.org/about/stats/> because it's leading. It's only off by an insignificant 10% of all users.
* Let's henceforth rely on our data. TODO remeasure, compare change.
* Let's henceforth rely on our data. ...remeasure, compare change.
* Found less than 2.2% use PHP 7.2 or lower (1.8% uses 7.2)
* Moved TSF installation hanlder to a different file.
* Improved letter spacing from logos.
TODO remove png files, all browsers support svg now.
Expand Down Expand Up @@ -103,8 +104,6 @@ TODO (FIXED, clean up) instead of a fancy observer on logger, we might simply ju
TODO Reevaluate get_view()'s implicated extract() and the use of get_defined_vars()
- Neither of these can be populated by the user, still, they are an exploit waiting to happen.

TODO we use hrtime(), PHP 7.3+.... ooops?

= 2.5.3 =

**Release date:**
Expand Down
4 changes: 2 additions & 2 deletions the-seo-framework-extension-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* Plugin Name: The SEO Framework - Extension Manager
* Plugin URI: https://theseoframework.com/extension-manager/
* Description: Add more powerful SEO features to The SEO Framework. Right from your WordPress dashboard.
* Version: 2.6.0-dev-10
* Version: 2.6.0-dev-11
* Author: The SEO Framework Team
* Author URI: https://theseoframework.com/
* License: GPLv3
* Text Domain: the-seo-framework-extension-manager
* Domain Path: /language
* Requires at least: 5.5
* Requires PHP: 7.2.0
* Requires PHP: 7.3.0
*
* @package TSF_Extension_Manager\Bootstrap
*/
Expand Down

0 comments on commit 9a2e431

Please sign in to comment.