-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bump minimum PHP version requirement to 5.4 and include FasterImage library dynamically #1809
Conversation
@@ -172,38 +172,7 @@ private static function determine_which_images_to_fetch( &$dimensions, &$urls_to | |||
* @param string $mode Whether image dimensions should be extracted concurrently or synchronously. | |||
*/ | |||
private static function fetch_images( $urls_to_fetch, &$images, $mode ) { | |||
// Use FasterImage when for compatible PHP versions | |||
if ( 'synchronous' === $mode || | |||
false === function_exists( 'curl_multi_exec' ) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This curl_multi_exec()
call gives me pause. Is it possible for this function to not exist in 5.4, say if an older version of cURL is used? We've seen something like this when an older version of ICU is present: #1440
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curl_multi_exec()
should be available on any PHP5 version as the PHP docs state, at least their is no distinction between different sets of curl_*()
functions. In other words, if curl_exec()
exists, we can also assume curl_multi_exec()
exists. Note that WordPress core does that as well, in their cURL implementation they use curl_multi_exec()
too and don't specifically check its existance. I think we should move forward with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently this turned out to not be true: #2183 (comment)
The build is just failing due to a PHPCS error:
|
The PHPCS fixes are opening a snowballing can of worms 😄
|
We should actually do a PHPCS cleanup task to get the entire repo up-to-date with the latest WPCS 1.2.x standard anyway. |
Question: Why go the route of patches vs forking the repo and commit directly do it? That's what I did for PHP-CSS-Parser. Seems it could be easier to maintain the patches that way? |
@westonruter I opened #1810 to update and fix all coding standards errors. Let's merge that one first, then I'll pull it in here, fix merge conflicts to make it pass. |
…s and deprecate it on the public method.
I think for simple tweaks the patching workflow is more pragmatic since that allows us to manage everything from this repository. Looking at the PHP-CSS-Parser, the custom tweaks there are more complex, so that justifies a fork. I suggest we use the patching approach for now with this dependency. If and once we need to make more changes, we can use our best judgement to at some point decide the patching approach isn't viable anymore, and then we could move to a forked repository. |
…rimage-security-fix * 'develop' of github.com:ampproject/amp-wp: Re-switch php-compatibility from wimg to phpcompatibility; pin at v9.1.1 Remove unnecessary CommentedOutCode ignore Revert "Update WPCS and PHPCompatibility to latest versions and rely on lock file for concrete versions." Fix all outstanding coding standards violations, via PHPCBF, adjustments to phpcs.xml and manual modifications. Remove outdated WPCS annotations that are no longer preferred. Update WPCS and PHPCompatibility to latest versions and rely on lock file for concrete versions.
Fixed as of 69543ed. To run a build to create an
This is a great question. This has not been a consideration that has been made when making a release. But which dependencies would be a problem here? |
$urls = array_keys( $urls_to_fetch ); | ||
$user_agent = apply_filters( 'amp_extract_image_dimensions_get_user_agent', self::get_default_user_agent() ); | ||
$client = new \FasterImage\FasterImage( $user_agent ); | ||
$client = new \FasterImage\FasterImage( $user_agent ); // @todo The $user_agent is not actually able to be passed in this way to FasterImage. Needs another patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something we should fix as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixarntz What is the workflow to add a new patch?
I'm guessing we will want to do something like this here:
--- a/wp-content/plugins/amp/third_party/fasterimage/FasterImage.php
+++ b/wp-content/plugins/amp/third_party/fasterimage/FasterImage.php
@@ -25,7 +25,25 @@ class FasterImage
*/
protected $timeout = 10;
- /**
+ /**
+ * User agent.
+ *
+ * @var string
+ */
+ protected $user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36';
+
+ /**
+ * FasterImage constructor.
+ *
+ * @param string $user_agent User agent.
+ */
+ public function __construct( $user_agent = '' ) {
+ if ( $user_agent ) {
+ $this->user_agent = $user_agent;
+ }
+ }
+
+ /**
* Get the size of each of the urls in a list
*
* @param array $urls
@@ -115,7 +133,7 @@ class FasterImage
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
# Some web servers require the useragent to be not a bot. So we are liars.
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36');
+ curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
"Cache-Control: max-age=0",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this now.
What I currently do is I have a local checkout of the FasterImage library in the tagged version that we're using. I apply the existing patch against it, change code, recreate the patch again.
Note that you can't just use the master
branch since it contains code that isn't part of a release yet. However, for future releases, our patch file will just apply until something in that same area changes, which would naturally cause a merge conflict. Composer would notify us about that.
Generally, anything for which we don't specify a fixed version number is a problem. For example, if we say However, it is a good practice to not specify fixed versions, but rather rely on semantic versioning (I suggest we use I added a |
Normally yes, but we don't need to worry about that now because Renovate will take care of making sure that each dependency is updated. It will set the dependency on fixed versions so that we can be sure that a tagged version will always have the exact same versioned dependencies at the time of tagging. It's also true that the |
@westonruter That's fine with me then. We should still keep the |
Great changes! 🎉 Good work. |
…velop-to-1.0.2 * 'develop' of github.com:ampproject/amp-wp: (26 commits) Fix PEAR.Functions.FunctionCallSignature phpcs issues Strip old-school CDATA and HTML comments from XHTML-compatible style elements Re-simplify condition include_manifest_comment; remove undefined constant Add tests for style sanitizer include_manifest_comment option Introduce when_css_excluded option for include_manifest_comment arg Suppress style[amp-custom] manifest HTML comment when not WP_DEBUG Add missing vendor deps to build after #1809 Update dependency xwp/wp-dev-lib to v1.0.1 Add wp_generator to classic post template Remove Powered by WordPress in classic footer template Fix broken unit test as it is just as valid now. Remove unnecessary strlen() call. Ignore the home URL's path if present when normalizing image URLs. Go back to using site_url() in AMP_Style_Sanitizer and harden concatenation of relative URLs. Remove redundant composer install Only set CHECK_SCOPE=all on Travis (see #1822) Improve sanity check instructions in release steps Pin wp-dev-lib to 1.0.0 Eliminate references to submodules from contributing.md Remove obsolete DEV_LIB_SKIP of composer ...
…alidation-performance * 'develop' of github.com:ampproject/amp-wp: (107 commits) Remove unnecessary home option setting; only register theme dir when needed Fix tests related to home/siteurl when WP_HOME/WP_SITEURL are set Fix test_get_validated_url_file_path to account for custom content dir Fix PEAR.Functions.FunctionCallSignature phpcs issues Strip old-school CDATA and HTML comments from XHTML-compatible style elements Re-simplify condition include_manifest_comment; remove undefined constant Add tests for style sanitizer include_manifest_comment option Introduce when_css_excluded option for include_manifest_comment arg Suppress style[amp-custom] manifest HTML comment when not WP_DEBUG Add missing vendor deps to build after #1809 Update dependency xwp/wp-dev-lib to v1.0.1 Add wp_generator to classic post template Remove Powered by WordPress in classic footer template Fix broken unit test as it is just as valid now. Remove unnecessary strlen() call. Ignore the home URL's path if present when normalizing image URLs. Go back to using site_url() in AMP_Style_Sanitizer and harden concatenation of relative URLs. Update package-lock.json after re-install Fix readme date and typo Remove redundant composer install ...
…ce-worker * 'develop' of github.com:ampproject/amp-wp: (335 commits) Ensure that amp-fx-collection is included when amp-fx attribute is present Manually enqueue amp-lightbox-gallery component when lightbox attribute is present Add failing test for amp-img[lightbox] not causing amp-lightbox-gallery to be enqueued Remove unnecessary home option setting; only register theme dir when needed Fix tests related to home/siteurl when WP_HOME/WP_SITEURL are set Fix test_get_validated_url_file_path to account for custom content dir Fix PEAR.Functions.FunctionCallSignature phpcs issues Strip old-school CDATA and HTML comments from XHTML-compatible style elements Re-simplify condition include_manifest_comment; remove undefined constant Add tests for style sanitizer include_manifest_comment option Introduce when_css_excluded option for include_manifest_comment arg Suppress style[amp-custom] manifest HTML comment when not WP_DEBUG Add missing vendor deps to build after #1809 Update dependency xwp/wp-dev-lib to v1.0.1 Add wp_generator to classic post template Remove Powered by WordPress in classic footer template Fix broken unit test as it is just as valid now. Remove unnecessary strlen() call. Ignore the home URL's path if present when normalizing image URLs. Go back to using site_url() in AMP_Style_Sanitizer and harden concatenation of relative URLs. ...
As pointed out in chat, we should address the unnecessary TLS verification being disabled in the FasterImage library. While doing that, a few other issues arised:
This PR implements the following changes:
curl_setopt()
calls made by the library.Considerations:
patches
folder is ignored in that process.composer.json
as minimum, not as "the dependencies have to be installed in a version compatible with that".