Asked  7 Months ago    Answers:  5   Viewed   26 times

As the title says, I want to know if it is be possible to automatically launch a PHP script when a restart of apache is done.

MORE INFO EDIT:

I will try to explain what is the purpose of this, the best I can. We are currently refactoring our application and we'll be stuck with 2 differents configuration file system for the time being, until all of the application flows are refactored (might take more than a year). The old one is using simple flat file in the key=value format (i.e. www.conf), while the new system will use cacheable php files (i.e. www.php). We need to replicate to www.php any config changes made in www.conf.

Since Apache gets restarted whenever there is a config change in www.conf, I thought it might be a good workaround solution to launch a PHP script, that would replicate the www.conf to www.php.

 Answers

25

You need to modify you startup script for your apache.

Open your startup script, it should be in /etc/init.d/apache or apache2

Search for the start / restart section and add your cli call for your PHP script.

Example:

    restart)
            [..]
            php -q /tmp/myscript.php &
            ;;

Where /tmp/myscript.php is your php script that you want to launch.

The "&" at the end will start the script in the background so your startup will not wait until your php script has ended. If you want to wait until it has ended, remove the &.

You should not put such thing into your startup scripts, there might be better solutions. What are trying to achieve?

Wednesday, March 31, 2021
 
millenomi
answered 7 Months ago
67

Apparently, when you access a VirtualHost through the alias, there is no trace of the original SERVER_NAME in any of the $_SERVER variables.

The only idea that comes to mind is setting an environment variable:

SetEnv MY_HOST host1.example.com

this should set the value of $_SERVER["MY_HOST"] to the correct host name. No guarantees though, I have never tried this in practice.

Wednesday, March 31, 2021
 
hjalpmig
answered 7 Months ago
67

I found a ready-to-use solution on Github.

It's called GzipBloat and it does exactly what I was looking for.

First you generate a 10GB gzip file (10MB after first compression) filled with input from /dev/zero

dd if=/dev/zero bs=1M count=10240 | gzip > 10G.gzip

In PHP you then set the content encoding and send the gzip file to the client.

header("Content-Encoding: gzip");
header("Content-Length: ".filesize('10G.gzip'));

//Turn off output buffering
if (ob_get_level()) ob_end_clean();

readfile('10G.gzip');

Results (Win10):

  • IE11: Memory rises, then IE Crashes
  • Chrome 52: Memory rises, error is shown
  • Edge 38: Memory rises, then drops and nothing is displayed (seems to load forever)
  • Nikto: Scans in regular speed, no memory problems
  • SQLmap: High memory then crashes
Friday, May 28, 2021
 
Sabya
answered 5 Months ago
12

First of all, what is the version of PHP?

If other .php scripts work except for phpMyAdmin, the is pretty safe to assume something is wrong with phpMyAdmin installation. (either with the files or the Virtual Host)


Troubleshoot:

  1. Can you run another script in phpMyAdmin directory? Try with a file containing phpinfo(); If it does not work then the problem is in your apache configuration.

  2. If the above is true, then the parser is not recognising phpMyAdmin/index.php as a php file, for some reason. Try reinstalling phpMyAdmin.


Thoughts:

Remove AddType application/x-httpd-php .php. You should not need it.

In PHP 5.4 magic_quotes_gpc was removed. If you're running PHP5, remove that line.

As of PHP 4.0.3, track_vars is always turned on, so remove it also.

As of PHP 4.2.0, register_globals this directive defaults to off. In PHP5.3 register_globals is deprecated, as of PHP5.4 register_globals was removed. SO if running PHP > 4.2.0 remove that line.

Saturday, May 29, 2021
 
vuliad
answered 5 Months ago
52

I hate to be this person, but...

That is not the way node is designed, it is designed to use the event loop, I would recommend having node serve the static files, maybe using apache as a proxy, then when someone requests a certain page, doing what ever needs to be done, if you really must spawn a child process, use child_process.spawn, as for the rights of the user, I recommend just passing in a code, like 1=admin, 2=user, 3=guest, and the child process can do what is needs.

Saturday, October 2, 2021
 
Averroes
answered 2 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :