I need to execute a scheduled task each minute that performs data extraction from MS Server.
Yet trying with bat script the php, would cause errors not recognizing sqlsrv functions
here is the content of the bat file:
cd C:\wamp\bin\php\php5.3.13
PHP C:\wamp\www\bin\Scripts\MinutelyScript.php
the MinutelyScript.php file works fine if executed from the server.
Please help me :)
Add this to your batch file
//path to your website
cd \wamp\www\yourwebsite
c:\wamp\bin\php\php5.3.5\php-cgi.exe -c c:\wamp\bin\php\php5.3.5\php.ini -f cronfile.php
"cronfile.php" if file is at root folder if it is inner folder give path from root folder
Related
So I have a a php script I'd like to run from a bash file script.sh. This is the code:
#!/bin/bash
/usr/bin/php /var/www/html/folder/file.php
The php file sends push notifications to an iOS app. The only way it works for me is if my current directory is /var/www/html/folder/ and the script is also in this
directory. So if I cd .. and try to do
x#x:./folder/script.sh
I get an error from the php file saying "unable to connect to ssl://gateway.sandbox.push.apple.com:2195(Unknown error)". I've also changed the permissions for both the php and bash file to rwx for all. Any ideas why it fails if everything isn't in the same directory?(Using Ubuntu)
As Etan Reisner pointed out, my php file included credentials/keys referenced locally. Referencing them with absolute paths fixed the problem.
I m trying to execute batch file in php file. I m using Apache server. Itried following ways but its not working
PHP Code
echo shell_exec('download.bat');
echo exec('download.bat');
system ("cmd /c download.bat");//Also tried for exec and shell_exec
Batch file contains downloading code using ftp client
Batch file
"c:\program files\coreftp\coreftp.exe" -s -O -site mysite -d /Export/*.* -p C:\wamp\www\file\txt
If I run it in cmd or run directly then its works fine when I run its in php its just write or echo batch file's code
download.bat file is in same folder.
I also tried to call simple bat file
start "link" "https://www.google.co.in/?gfe_rd=cr&ei=NzuIVI-FG6aG8Qef44CAAw"
Its also not calling to this bat file
Are you sure that your 'download.bat' file is in the same PATH as your PHP script?
Try to use absolute path like this
exec('C:\\MY\\PATH\\TO\\download.bat');
Just use exec('download.bat'); if the file is in the same directory, however you need to ensure that Apache has correct permissions to execute the batch file i.e. it should be running on an Administrator account. If you're on Win7 or above, look at how to run programs in elevated mode.
I created a php script for generating RSS feeds which is to eventually be run via a Cronjob.
All the php files and the resulting RSS xml will be within a sub folder in a website. The php script runs fine on my local dev if I use terminal or the browser while within the same directory on my local development machine.
e.g. php /Library/WebServer/Documents/clientname/siteroot/rss/dorss.php
works fine as does navigating to the dorss.php file in Chrome.
The CronJob has executed though with errors related to the fact that it cannot find the files specified with require_once() which are located in the same folder as rss or in a subfolder of that.
Long story short I need to have the Cronjob run from within the same directory as the dorss.php file so it can reference the include files correctly.
My knowledge on setting up a cronjob is VERY limited so I wanted to ask if this is at all possible (Change directory before running command) to do this on the same command line of the crontab or if not how can it be achieved please?
The current cronjob command is
0 0,6,12,18 * * * /usr/bin/php /var/www/vhosts/clientname/stagingsite/rss/dorss.php
TIA
John
You can change directory to the one you want and then run the php from that directory by doing this:
cd /var/www/vhosts/clientname/stagingsite/rss/
&&
/usr/bin/php dorss.php
It's easier than creating bash scripts, here is the result:
0 0,6,12,18 * * * cd /var/www/vhosts/clientname/stagingsite/rss/ && /usr/bin/php dorss.php
I don't know if there's a better solution, but I would suggest to write a bash script that changes to the correct directory before executing the PHP file, and use cron to execute this script. E.g:
#!/bin/bash
cd /Library/WebServer/Documents/clientname/siteroot/rss/
php dorss.php
Or even just:
#!/bin/bash
php /Library/WebServer/Documents/clientname/siteroot/rss/dorss.php
Save it somewhere and use cron to run that.
I have 2 php files. One which stores various xml files in a database and other php files takes those xml files as input, parse them and produces a another table having various information about the xml files.
I want this work to be scheduled for everynight.
I want to do this via batch files but I have no idea how to use .bat files, and how to incoorporate the php script in it.
Need help/guidance.
Thanks.
Yogesh
I assume you are doing this on a windows machine as you mention a .bat file
PHP can be executed from a command line e.g. a dos shell
http://www.php.net/manual/en/features.commandline.introduction.php
Once you get it working manually just put what you are typing in a text file. (.bat)
You can execute the .bat file (a program file to windows) when you want using a scheduler, e.g. http://windows.microsoft.com/en-GB/windows7/schedule-a-task
create start.sh add this code:
#!/bin/bash
php /path/to/folder/script.php
chmod 644 script.php
OR
create start.sh add this code:
#!/bin/bash
/path/to/folder/script.php
chmod 755 script.php
the first line of your script.php has to be:
#!/usr/bin/php
I have a PHP script that runs this command:
system("pdftohtml -i -noframes /home/myacc/pdfs/test.pdf");
When I run this from within public_html, an html file called test.html is successfully created and is placed in the public_html folder. However, when I run this from a cron job outside of public_html, no html file is created in any folder on the server.
Can anyone help me find where the resulting html file will be?
Thank you.
The problem lies in how cronjob work. Try to use the absolute location to pdftohtml.
Also, from your comment, you can't change how pdftohtml write the output. However, there's a trick to workaround this. That is by using custom shell script:
#!/bin/bash
cd /path/to/output/
/path/to/pdftohtml -i -noframes /home/myacc/pdfs/test.pdf