Is there any way to execute PHP compiled?

If I understand correctly, PHP is a very “straight forward” language.

For example:

  $x = "Hi"
  echo $x;

This should be outputted as Hi to the user and nothing we would put inside the code block will prevent this from happening or change the output that the user gets.

For example, pseudocode:

  $x = "Hi"
  echo $x;
  search_and_replace($x, '') // Pseudocode line

This will not cause Hi to be deleted (by turning it into an empty string), because Hi was already outputted as-is to the user.


If PHP were compiled instead line-by-line interpreted we could indeed manipulate pervious PHP data focally.

Is there any way to execute PHP compiled?

Compiling it would make absolutely no difference to the result.

But how can this be?
I mean,
If PHP “broadcasts” line after line to the end-user (as long as it’s not an empty line or a code comment line) than why not?
Why a compilation wouldn’t allow to “bias” previous code segments in the same document?

Because that’s not the way compilers work.

I think I am wrong in relating to compilers more than I should but if a compiler gets some input and translates it to the output (which can be input) in another language, than I assume that it can also bias an early code segment, example pseudocode:

$x = 1
echo $x
// 2 is echoed

In theory, a compiler programmed to do so could change 1 to 2 just before runtime is finished. You might say that it’s useless but would you really say it’s impossible?..

Of course not!

The value was output in the previous statement when its value was 1. You can change the value of x, but you can’t change what has been output.

If you want capture whatever PHP outputs so you can manipulate it later you can use ob_start().

This is what most frameworks use too, to prevent showing partial pages and then an error. It will either show a full page or an error.

Naturally with the current release of PHP — yes, of course not…

But if I could ask the interpreter to postprocess the code somehow, it might work !

Perhaps ob_start() mentioned by @rpkamp could be useful for me…

What is the real problem you are trying to solve?

A content management system creates some HTML link elements which I don’t want.
Removing these elements via CSS (display:none) or JavaScript (remove()) isn’t useful because then crawlers could still access any webpage linked from these elements.
I don’t want to remove the PHP creating these elements directly from the complex content management system source code but I still want them not to take effect and I am not sure how.

What cms are you using. There might be a better option to remove these specific elements based on the cms. Many cms platforms have ways to alter output through various post processing mechanisms. There might also be a way to prevent the link from rendering by adding code outside the source itself.

How about just commenting out the code that shows the links?


I didn’t find anything that takes care of these links, as these are heavily hardcoded in that CMS.

A phenomenon I don’t know in Drupal/WordPress/Joomla.

As with deleting, due to the hardcoding nature of MediaWiki this requires broad studying of the PHP MediaWiki source code which at least now I as a non PHP programmer cannot do, hence I seek postprocessing as I have described already.

Such postprocessing would allow me to change any element, based on its CSS selector, into an empty string, or something of that sort, I guess.

An alternative we’re using quite often at work is to proxy the site through NGiNX and use sub_filter.

Just make sure to request the page from the origin without any compression, otherwise it won’t work.

upstream website.tld {
  keepalive 4;

  server {IP OF ACTUAL SERVER BEING PROXIED}:443; # Or 80 if using HTTP

server {
  listen 443 ssl;

  location / {
    proxy_pass https://website.tld; # or http:// if applicable
    proxy_set_header Connection ""; # Prevent sending Connection: close from client to backend
    proxy_set_header Accept-Encoding ""; # no compression allowed or sub_filter won't work
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_http_version 1.1; # Default is HTTP/1, keepalive is only enabled in HTTP/1.1

    # This will actually remove the link
    sub_filter_once off;  # Replace all occurences, not just the first one
    sub_filter '<a href="/some/link">Foo</a>' '';

And then point the DNS for website.tld at the proxy server instead of the actual server.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.