Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
cron job - sessions -
Old 02-10-2012, 07:44 PM cron job - sessions -
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Hello,

I am not very familiar with cron jobs, I have a script that runs once a day, it sends an email with daily reports. I'm not sure how cron jobs work, how they run the page or anything, so i was wondering if i have a php script that at the moment it runs opens a pop up window depending if the user is logged in, will it work if it is run with the cron job? i hope it makes sense, it might be a stupid question but i have no idea if this is even possible..

i would have something like this

if($user == $_SESSION['username']){
echo 'pop up window';
}
else{
echo 'email to the user;
}

Thanks for your help
stivens is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-10-2012, 08:55 PM Re: cron job - sessions -
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Not sure I understand what you're asking.

The code you posted wouldn't make sense for a script that is intended to be executed by cron because there is no user. I'm not even sure if you can successfully start a session in this case, but it certainly wouldn't work as you expect it to.

Quote:
so i was wondering if i have a php script that at the moment it runs opens a pop up window depending if the user is logged in
PHP scripts do not open up pop up windows. The output generated by a PHP script might indicate to a user's browser that it should open another window, but the PHP script is not 'aware' of this. If you have a PHP script that spits out some HTML and JS that, when parsed by the users browser, opens a popup it won't work as expected as a cron job; there is no browser to parse the output and open the popup.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 02-10-2012 at 09:02 PM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-13-2012, 03:01 PM Re: cron job - sessions -
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
So, what I'm guessing you need is that if the user is on-line, he'll get a popup {else} he'll get a mail. You didn't say if you need the report to be delivered at some specific hour so, I will just suppose you need it "once a day" at any hour he'll be online. If he will never visit, at the end of the day will get a mail.

1. The user is online and at some point he visits the website. When he's logged in you also know he's there and you can deliver that report as a popup AND you also mark it in your database as "send for GEORGE".
2. At the end of the day you only send reports for those users that didn't get the popup.

From my experience, you should do both (show a popup when he's online and send him an e-mail at the end of the day)... a popup may be accidentally closed and he might loose the report. If you send it on e-mail it's safer.
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 02-13-2012, 06:21 PM Re: cron job - sessions -
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Quote:
Originally Posted by vectorialpx View Post
So, what I'm guessing you need is that if the user is on-line, he'll get a popup {else} he'll get a mail. You didn't say if you need the report to be delivered at some specific hour so, I will just suppose you need it "once a day" at any hour he'll be online. If he will never visit, at the end of the day will get a mail.

1. The user is online and at some point he visits the website. When he's logged in you also know he's there and you can deliver that report as a popup AND you also mark it in your database as "send for GEORGE".
2. At the end of the day you only send reports for those users that didn't get the popup.

From my experience, you should do both (show a popup when he's online and send him an e-mail at the end of the day)... a popup may be accidentally closed and he might loose the report. If you send it on e-mail it's safer.
Yes i am trying to do both, show the pop up and send the email. the job runs every 15 min. it is not a report, it is an alert to remind the user the pending task he has at the time the job runs. the user should be online all day. the problem here is there is no way to find out if the user is online running a cron job is it?
stivens is offline
Reply With Quote
View Public Profile
 
Old 02-13-2012, 06:42 PM Re: cron job - sessions -
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
so i was wondering if i have a php script that at the moment it runs opens a pop up window depending if the user is logged in, will it work if it is run with the cron job?
No and No.

PHP runs on the server and once the page is delivered to the client browser cannot affect anything.

To do what you require will need Java applets/servlets. (That's JAVA not javascript.)
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-13-2012, 07:02 PM Re: cron job - sessions -
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Thanks.. im gonna have to find another way to achieve this :/
stivens is offline
Reply With Quote
View Public Profile
 
Old 02-15-2012, 05:08 AM Re: cron job - sessions -
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
Quote:
Originally Posted by stivens View Post
Yes i am trying to do both, show the pop up and send the email. the job runs every 15 min. it is not a report, it is an alert to remind the user the pending task he has at the time the job runs. the user should be online all day. the problem here is there is no way to find out if the user is online running a cron job is it?
If you want to do both, just run the cron once a day (send one mail per day) and after the user gets the popup (if he does) you mark in his `users` table a flag "gotTheMaiToday" = date(Y-m-d) and every time you check if `gotTheMaiToday` is NOT today ( != date(Y-m-d) )

You also can know if the user is online in a cron job, but you will have a margin of error.
After he is loggedIn you can show the popup and you also mark a flag - a new column in the users table (let's say "LastAction" - datetime, default = 0) so at every user action (every page he will access) - you can have this in your config file or, some file that is everywhere - you update the `LastAction`. Something like this
PHP Code:
<?php
# any action he takes, any page he visits
# this can be in some common (config) file
if( ISLOGGEDIN ) {
    
executeQuery '
        UPDATE `users` SET `LastAction`=NOW()
        WHERE userId="hisIDFromSession"
    ' 

}
In the cron, check if the user was online in the last (let's say) 15 minutes.
If he doesn't do anything for 15 minutes that means he's not active anymore.
So, you have
Code:
SELECT `userId` FROM `users`
WHERE CURRENT_DATE < DATE_ADD(LastAction, INTERVAL 15 MINUTE)
And you get a list (of IDs) with all users that are on-line.
__________________
you can
Please login or register to view this content. Registration is FREE

Last edited by vectorialpx; 02-15-2012 at 05:22 AM.. Reason: add code
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Reply     « Reply to cron job - sessions -
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.96805 seconds with 12 queries