Running Custom Files In Command Prompt

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
kirondedshem
User
Posts: 642

Running Custom Files In Command Prompt

Post by kirondedshem »

I am tring to write a php file which runs some queries in hope of linking it to a scheduled job. And for this after I create the php file, I test it by running it in the browser and it wotks well But on running it from command prompt which I feel is ideally how they will be run in scheduled tasks or cron jobs.

I once tried to create a similar php file while i was using mysql and it kepts on generating errors when run in command prompt so in the end I had to do my own database connection using mysqli and got it to do the job. But no that am using postgresql I would like to avoid going into manual db connection So I want to use either ew_Execute functions or DbHelper and make it work when run in command prompt as well.

Has anyone ever created a custom files and used either ew_Executes or DBHeper fucntions and it still runs well when called from command prompt, are here thing I should look out for when creating it for command prompt. Whats the right way to go about this etc etc.

Thing ive tried:
NOTE:All these still run my queries in the browser BUT wont run successfully when called from command prompt
-creating a custom file with common files ticked and header and footer and then use ew_ExecuteHtml("some query")
-creating a custom file with common files ticked and header and footer and then use DBhelp->ExecuteHtml("somequery");
-creating a custom file with common files ticked and NO header and footer and then use ew_ExecuteHtml("some query").
-creating a custom file with common files ticked and NO header and footer and then use DBhelp->ExecuteHtml("somequery");
--creating a custom file WITHOUT common files ticked and include dbehlper.php required files only manually and then use DBhelp->ExecuteHtml("somequery");.

NOTE:I know I can achive this if I manually make the db connection but it looses the purpose since I already have dbhelper I would want to use that instead, so any help in highly appreaciated


digitalphotoworld
User
Posts: 416
Location: Nürnberg/Germany

Post by digitalphotoworld »

What about using the mysql event scheduler? It is pretty simple to use and works very well. I use it for some bigger sql-scripts that are running each night and clean-up some tables, logs etc.


kirondedshem
User
Posts: 642

Post by kirondedshem »

Thanks for the reply but
As I mentined earlier, This project Is using Postrgesql, and am thinking from a perspective that does not tie me to the database I use wether sql server, mysql, postrgesql etc, thats why am looking to use dbhelper which also accounts for the same.

using the mysql event scheduler.
I could have use PGAgent in Postgresql but the automation I want is not at the db level.

The queries I want to run are not static like leaning up tables or mirrroring data etc. I am trying to generate intelligent notifications based on a bunch of activities in the system as well as cummulative addittions to the system or critical events performed on the system since the system am working on does monitoring of some data that comes in. Where due to the complexity of the logic I need to automate what the notification looks like to different users, what data they see from it etc I must apply it at the application level ie using php to determine what queries I need to run as well as how I format the HMTL that will be generated for each notification as I also need to send the notifications over various means like email, etc.


digitalphotoworld
User
Posts: 416
Location: Nürnberg/Germany

Post by digitalphotoworld »

Can you explain why you need running the files from command prompt?


kirondedshem
User
Posts: 642

Post by kirondedshem »

Can you explain why you need running the files from command prompt?

I am building a system which has an api linking to an andoird app somewhere. The android app frquently sends me data information form the various mobile app users. The api is responsible for getting the information, save sit into my postgresql db. After this I create various reports and dashboard pages to make some summaries of this information to soem key users who have access to login to the web protal.

Now I have a new requirement where most of these users dont have time to login and use the various reports to make some key decisions that each of them is responsible for. And for this reason I have a new requirement To automatically generate summaries that help such people make key decisions on how to porgress while in the field, were after I have to foward this information to them as soon as possible at an hourly basis. These summarised reports can be like "5 phones are not boradcasting", "You have aerned 5USD in the last one hour" etc etc.

Now I can formulate teh logic to create those summaries and save them in my notifications table. Where Afterwards I can pick them and send them vis thier respective emails.

BUT This porgress should be automated, I should run automatically at set time intervals. That why even though I can create the php files, I still need a cron job or a task scheduler to call these php files at set intervals for me (Ive done this before SO I know as long as the php files can be called in command prompt using "php -f c:\my_project\my_file.php") It can be scheduled by an external process.

Problem is When using phpmakers ew_execute or DHHelper, it somehow generates alot of php errors unlike when run from the browser. I know I can sole this by writing the basic connection strings myself and perform the database operations using the default php functions for the respective databases. I just feel using DHhelper I can achive the same but In a much cleaner way.


digitalphotoworld
User
Posts: 416
Location: Nürnberg/Germany

Post by digitalphotoworld »

Okay, after reading your post three times, I think I understand what you want.

I have a similar scenario in that I sent mass-emails. The problem with sending a huge amount of emails, is a possible server-timeout. For this I using a cron-job that is loading a page that is public avaible. The filename of this file is for security reasons very long and contains a token.

The trick is accessing the file via WGET and the parameter --spider.

Just type wget http: // www . your-domain . com / your-secret-script . php --spider into the console of your server.


kirondedshem
User
Posts: 642

Post by kirondedshem »

Just type wget http: // www . your-domain . com / your-secret-script . php --spider into the console of your server.

Am STill developing this module on my local windows machine and as for console. am using command prompt.
SO I dont think I can call an http page directly like http:://localhost/my_project/my_file.php in command prompt. ALthough calling what you gave me in a webservice or through a browser works well
BUT I know if ive added php to my enviroment variables I can us php itself and I tell it to execute for me a php file call it like php -f c:\my_project_path\my_file.php. I also us a smilar format when I deploy on a linux machine.

NOTE:Ive used this "php -f c:\my_project_path\my_file.php" method for quite some time on a number of projects and so am sure it works As I have some php scripts that send emails as well as do database backup automatically and they all still run fine. BUt thats just coz am doing the database connection manually unlike what am trying to approcah.

@digitalphotoworld
If you are using ew_Execute functions or DBhelper functions in the custom files
SO Can you try running any of the your-secret-script . php files using the php itself in command prompt and tell me if it works on your end. And If its working, can you see your database changes after it has run.

If all the above works then please guide me on how you to go about making ew_Execute or DbHelper owrk if called from a command prompt.


kirondedshem
User
Posts: 642

Post by kirondedshem »

Thanks @digitalphotoworld after downloading wget it can call my file fine. But am worried if I dont stick to the basic principals of running php files using thier respective engine rather than calling them remotely through something like wget. I might not be able to run them successfully if I deploy on other enviroments which dont have wget installed and I have to use do it the right way using cron jobs and such.

So your solution works fine for now But I still want DBHelper or the ew_Execute fucntions to work when called by the default php executors, As I feel I'll be solving the problem for good.


digitalphotoworld
User
Posts: 416
Location: Nürnberg/Germany

Post by digitalphotoworld »

If I use wget from linux command line (by typing it or with cron job) in both cases I can use all the build-in-functions from PHPMaker. With wget the script is working as if I use a browser and access the site via http.

By the way: Some of the scripts that I call with wget are not on the same server. If you have cases where it is not possible to use a cronjob on a server or install additional packages, just use a "own" servers and call the scripts from this server.


kirondedshem
User
Posts: 642

Post by kirondedshem »

With wget the script is working as if I use a browser and access the site via http
just use a "own" servers and call the scripts from this server.
These are the key points that have won me over, its afr more useful than what ive been using

Thnaks I'll use this from now on


Post Reply