Running pdftohtml with PHP - can't find resulting HTML file - 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

Related

Execute PHP routines on Windows Server [duplicate]

How can I create a scheduled task to run a PHP file?
Yes, I filled out everything in the scheduled task, but it still doesn't work.
Run: "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\WEB\4w_website\save.php"
Start in: "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\WEB\4w_website"
It just opens the PHP file in Notepad.
I gave the correct user name and pwd.
Please help me..
The Run command should be
C:\Path\to\php.exe -f "C:\Path\to\file.php"
From the command line help of php.exe:
-f Parse and execute <file>.
I just wrote a .bat file that does the work file.bat
#ECHO OFF
php.exe -f "C:\code\cust.php"
And put it in the Schedule Tasks like this:
Run: C:\code\file.bat
Start in: C:\code\
If you running php scripts, in most of cases script awaiting to be runned in current folder.
That mean you must set up folder each your action, use field "Start In".
Example:
Run: C:\php\php.exe
Arguments: -f C:\web\myscript.php
Do not forget:
Start in: C:\web\
Sounds like you don't have PHP files associated with the EXE.
You can do this My Computer > Tools > Folder Options > File Types. If nothing else, this can also help you verify your settings for them.
Otherwise, you can specify "C:\path\to\php.exe [file]" in the task.
This is what I did:
PHP file
<?php my code goes here ?>
*Note if you are using HTTP API/CURL in CLI use dl("php_curl.dll");
this loads curl into cli
Now I added PHP to windows path variable, this can be done from My computer, properties, advanced settings, environment variables, new
Next I created a .bat file, simply open a notepad & type code below and save as myfile.bat
#ECHO OFF
php -f d:\wamp\www\V3\task.php
This site might help you on .bat file syntax.
Now create a new scheduled task on windows & call the above .bat file as source,
For those people that can't able to make #Tomalak's answer work:
Check if there are spaces () in your directory. If it does, you need to enclose them with ".
"C:\Path\to php file\php.exe" -f "C:\Path\to php file\file.php"
And if it still did not work, check your file.php if there are included files in it.
include("file2.php"); /* OR */
include_once("file2.php");
Remove it. And if the included file in your file.php is really needed, try to move the code/script from that included file to your main file.
I think, you must execute your PHP script via URL.
you can write batch script for execute URL.
Why you don't write backend script in other language such as batch script, vbscript or etc.

Can't properly execute php file within bash file if in differenct directory

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.

Running Cronjob from a specific directory

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.

How to run a php script through batch file for windows 7?

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

extract from mssql using php scheduled task

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

Categories