Parallels Plesk scheduling a task with wget command - php

I'm running Parallels Plesk on a Hostgator windows server. I am trying to set up a 'Scheduled Task' ie cron job running every 5 minutes that simply loads a webpage, nothing more. This is my current setup:
Unfortunately, nothing seems to work. I was ideally looking for something like wget "myurl" to keep it simple, but it doesn't look like it takes commands, only executables. I created a php script with a file_get_contents to load the page, and used the PHP installation as the executable passing the script location as the argument, but this doesn't work either. What am I doing wrong? What I am trying to achieve is so simple.

Looks like it happens because of spaces in path C:\Program Files (x86)\
Try to quoting full path to PHP binary.

Related

How can I run a daemon on xampp using PHP?

I have an XML database that I want to manage independently from users on my website. Looking into the matter it appears that I should write a daemon script to manage my database. That is all fine and dandy but, I feel like I'm opening a can of worms. I wanted to write my daemon script in PHP, so I looked into PCNTL. But I quickly learned that PCNTL is not suited for web servers. So now I am stumped. How can I get a daemon to run on my server? Do I need to learn another language? I only want to write my own scripts. But I feel lost. I would prefer to write my daemon in PHP as I am familiar with the language.
I have been researching everything from PCNTL, CLI, SO questions, numerous articles on daemon processes... etc
I am running PHP 5.6.32 (cli), windows 7, on Apache. XAMPP 5.6.32. Unix system.
EDIT: I also have windows setup to run PHP from command prompt.
There's nothing wrong in running a PHP daemon, however it's not the fastest thing, especially before the 7.0 version. You can proceed in two ways:
Using Cron Jobs, if you're under Unix systems crontab will be fine, in this way you can specify the interval within the system automatically executes the specified script and then exit.
The true daemon, firstly you need to change the max_execution_time in PHP.ini to 0 (infinite), then in your daemon call for first function set_time_limit(0);, remember to run it only once. However if there is some failure like a thrown error uncatched the script will exit and you need to open it again manually, and don't try...catch in a while loop because it will probably go into an endless loop. Execute the script with php -f daemon.php.

How can I to run php script from powershell-commandline?

How can i setup my powershell to run php scripts in like a commandcall like this
php test.php
I'm able to do this on a server at work which I connect to by putty, but would be nice if I was able to execute those scripts directly from my own without having some server running.
I also know about Xaml, which I don't like since its require you to refresh some browser.
You can do all the stuff suggested above or ...
Go to php.net and download the php file stack for windows.
Copy the file stack into say c:\php or if you want multiple versions, say c:\php5 or c:\php7 etc.
Open powershell and type c:\php\php.exe -h, you will get the php help output. Yay you are up and running, whoot.
(Note: you may need to rename php.ini.development -> php.ini
Advanced instructions:-
Type env into os search (cortana) and select environmental variables.
Add your php location to path (c:\php) and create a variable php (or php5 etc) pointing to c:\php\php.exe
Now you can run php in powershell with php (php -h to test).
Note: while not the question, this also works in the git bash shell.
I'm assuming windows since you said powershell. You can just install php on windows but that means also installing apache or enabling IIS.
Or there's apparently a built-in webserver for command-line functionality that might minimize the amount of headache involved in configuring that stuff.
This might help get you going also:
http://php.net/manual/en/install.windows.legacy.index.php#install.windows.legacy.commandline

Running continuous PHP (script) background processes on a WAMP server

I got the 140dev Twitter framework (which uses the Twitter phirehose) manually
running (via the webbrowser on my local wamp server), but I can't
figure out how to run both get_tweets.php and parse_tweets.php as a
background process like with SSH commands:
nohup php script.php > /dev/null &
Some of you started using (the Windows equivalent of) cronjobs, but
this isn't the right way to go. I think this is because of creating
multiple connection (or re-connections) to the Twitter streaming phirehose isn't allowed?
How can I run both PHP scripts (get_tweets.php and parse_tweets.php)
as a background process on my local WAMP server (and later on a VPS)?
Just to clearify:
I am using a WAMP server (first to test a little bit and later to
run it on a VPS)
Using LAMP or any *nix server/system isn't an option (due to time,
experience and lack of skills)
I have searched for solutions (on google and stackoverflow), but they are either not working or not clear enough for me (I am new to this)
Thank you in advance.
Find the php/bin folder where the php.exe is located. Copy the folder path and add it to your PATH environment variable (Follow this for instance to edit your PATH variable.
Once this is done, you'll be able to execute php in the command line from anywhere. Just start php script.php with a command line in the right folder and it should work. There might be some configuration to make so that the php in command line uses WAMP's php.ini.

"Running" a PHP file

I think this has to be a very simple question but I am not finding any answers for what I am trying to accomplish.
I have a PHP file which will send out emails. This part works. The thing is, I need this PHP file to "run" every 5 minutes.
My problem is not with the scheduling, I'm fairly certain I understand how to do that.
My issue is with the "running" of the PHP file.
My mind is totally void of any information of how to "execute" a PHP file rather than just make it open in a browser and spit its code everywhere.
I know that this PHP file works because when I am working on it in Dreamweaver and I click the "Discover" link where it says "Dynamically-related files for this document may have changed and should be re-discovered by the server" it executes this PHP file and I get my emails sent.
I've tried going through command line like THIS but all it does is spit out the php code as if I was running it in a browser. Nothing actually sends.
Is there some way to change the way the PHP file itself is formatted that would make it do this?
What is Dreamweaver doing when I click "Discover" that makes it work?
I feel like this should be a simple thing and its insane that I am not understanding it.....
Assuming you installed PHP with default settings, the PHP folder should be in your PATH variable. In which case, all you have to do is run the command php filename.php.
If not, you'll have to direct the command to where PHP is installed, maybe something like "C:\Program Files\PHP\php.exe" filename.php - either way, all you're doing is invoking the PHP binary on the file.
You have options. If it's a web page that you can access through your browser (and that sends the email as you'd expect), you can just request that page via HTTP every five minutes. Personally, I'd do this with cURL (e.g., curl.exe http://localhost/myfile.php). You can find Windows binaries here. You could also use PowerShell or something.
If this isn't a web page, or if you just don't feel like going that route, you can execute the PHP through PHP's command-line interface (CLI), as you've already figured out. C:\path\to\php.exe myfile.php will execute your code and spit the output to STDOUT. If everything is working with this except for sending email—which I'm guessing you're doing through mail—the issue may be with your PHP configuration. By default, PHP looks for the php.ini file in these locations. You can also explicitly tell the PHP CLI what php.ini file to use with the -c option (e.g., php.exe -c C:\path\to\php.ini myfile.php). Of course, you'll need to have everything configured properly in php.ini to send mail. This can be a bit trickier on Windows than on your average Linux machine with sendmail available.

Executing java from CLI via exec() under Windows

I have a PHP-script originally developed on Ubuntu, which now has to run on a Windows machine, executing a java program like this:
exec("java -jar {$filename}");
// Process output
This does not work as expected on Windows. I already found out, that although I can use java -version from the command prompt I can't use it in exec(), i.e. the problem is java can not be found.
I have a workaround in place, pointing to java.exe using the complete path to C:\Program Files\Java\...\java.exe if the script runs on Windows. Unfortunately though this is hardcoded to the path on the current machine, which might change or vary on a different system, e.g. when installing Java to a different location or a different version (JRE/JDK/6/7) is installed.
How do I call Java on Windows without having to refer to the exact location of java.exe?
You need to set enviroment variable on windows, to be able access java without path
http://www.java.com/en/download/help/path.xml
Even if this Question is a little older, I ran into the same problem and I found a pretty neat solution for it without the PATH requirement.
There is a symlinks to all java executabled located in this folder:
C:\ProgramData\Oracle\Java\javapath
for example: just call
C:\ProgramData\Oracle\Java\javapath\java.exe -jar XYZ.jar

Categories