Thursday 26 November 2015

PHP and long running processes

PHP and long running processes

It seems this question keeps coming up on the PHP newsgroups and, now that I've plugged into Stack Overflow - I keep seeing it their too:

How I do I start a PHP program which takes a long time to complete and how do I track its progress?

While these tend to attract lots of replies, they are usually wrong.

The first thing to consider is that you need to seperate the the thing which takes a long time from its initiation, the ongoing monitoring and whatever final reporting is required.

Since we're talking about PHP its fair to assume that in most cases, the initiation will be a PHP script running in a webserver. However this is not a good place to keep a long-running program.

1) webservers are all about turning around requests quickly - indeed most have failsafe mechanisms to prevent one request hanging about too long.

2) the webserver ties the request to both the execution of the script and to the client socket connection. Typically NOT keeping a browser window open somewhere waiting for the job to complete is an objective for the exercise. Although the dependence on the client connection can be reduced via ignore_user_abort() that was never its intended purpose.

3) long-running typically means it will have quite different resource requirements than a typical web page script - e.g. lots of file handles being opened and closed, more memory being consumed.

Most commentators come back with the suggestion of spawning a seperate thread of execution, either using fork or via the shell. The former obviously does not solve the webserver related issues if the interpreter is running as a module - you're just going to fork the webserver process. You've not solved any of the web related issues and created a whole lot of new ones.

You need to create a new process certainly.

The obvious type of process to create would be a standalone PHP interpreter to process the long running job. So is there a standalone interpreter available to the webserver? The prospective implementor would need to check (and whether the webserver runs as chroot). So lets assume there is, our coder writes:

print shell_exec('/usr/bin/php -q longThing.php &');

A brave attempt. However they will soon find that this doesn't behave as well as they expected and keeps stopping. Why? because all the process they created runs concurrently with the php which created it, it is still a child of that process. Now this is where it starts to get complicated. In our example above, the webserver process finishes with the users script immediately after it creates the new process - however it will probably hang around waiting to be assigned a new request to deal with. However at some point the controller for the webserver processes will decide to terminate it - either as a matter of policy because it has dealt with a certain number of requests (for apache: MaxRequestsPerChild) or because it has too many idle processes (apache's MinSpareServers). However the webserver process should not stop until all its child processes have terminated. How this is dealt with varies by operating system and of course, webserver. Regardless, the coder has created a situation which should not have arisen.

But on a Unix system there are lots of jobs which run independently for long periods of time. They achieve this by:
1) they are first started, say as pid 1234, and try to fork, say to pid 1235 after calling fork, pid 1234 exits
2) pid 1235 will become the daemon - it closes all its open fds including those for stdin, stdout and stderr
3) pid 1235 now calls setsid(), this dissociates this process from the tree of processes which led to its creation (and 
typically makes it a child of the 'init' process).

You can do all this in a PHP script, assuming you've got the posix and pcntl extensions. However in my experience its usually a lot simpler to ask an existing daemon to run the script for you:

print `echo /usr/bin/php -q longThing.php | at now`;

But how do you get progress information? Simple, just get your long running script to report its progress to a file or a database, and use another, web-based script to read the progress / show the final result.

Troubleshooting (updated Sep 2014)

Following on from the feedback I've received, there's a couple of things to check if it doesn't go according to plan.

The atd has its own permissions system implemented via /etc/at.allow and /etc/at.deny - see you man pages for more info.

On Redhat machines, the apache uid is configured with shell /bin/nologin - this will silently discard any jobs submitted to it, hence a more complete solution is:

putenv("SHELL=/bin/bash");

print `echo /usr/bin/php -q longThing.php | at now 2>&1`;







Monday 22 June 2015

10 Highest-Paying IT Security Jobs


According to a report issued by Burning Glass Technologies uncovers that employment postings over the IT security business have grown 74 percent somewhere around 2007 and 2013—double the rate of all other IT occupations. The Bureau of Labor Statistics is anticipating a 37 percent increment in Information Security Analyst positions alone somewhere around 2022.

With expanding concern around wholesale fraud, hacking, information security and protection, and with various prominent information breaks in the news, associations are multiplying down on their requirement for qualified, capable security experts. As anyone might expect, pay rates are expanding right along with demand.

Thus there is no doubt that the tech industry pays well. But the main question here is which job titles specifically make the most money in 2015 and which ones have tons of job openings? Here is a detailed list

1. CHIEF INFORMATION SECURITY OFFICER (CISO)

A CISO is a C-level administration official whose essential undertaking is to direct the general operations of an association’s IT security office and other related staff. The association’s general security is the preeminent concern of the CISO. CISOs make a middle compensation of $131,322, as indicated by PayScale’s 2015 evaluations

2. SECURITY ARCHITECT

A Security Architect is a senior-level worker who is in charge of building and keeping up the PC and system security base for an association. Security Architects make a middle compensation of $109,794. As indicated by PayScale, those on the lower end of the range make around $84,000, while the most generously compensated Security Architects win roughly $160,000.

3. SECURITY DIRECTOR

A Security Director is a senior-level representative whose assignment is to manage the usage of all IT efforts to establish safety all through an association. A Security Directors are in charge of outlining, overseeing and distributing assets to different security programs inside of an association’s security office; making client mindfulness and security agreeability instruction battles; collaborating with non-administration representatives; and offering key help to law in the case of a security investigation. Security Directors’ middle pay is variable, extending from $104,775 to $116,245. PayScale’s 2015 assessments find the pay range for Security Directors in the middle of $66,000 and $180,000.

4. SECURITY ADVISOR

Security Consultants work with customers to create methods for successful cyber security over their whole association. Notwithstanding knowing best practices and prescribed methods, they should likewise have strong correspondence, arrangement and venture administration abilities. Normal Salary: $198,909

5. DATA SECURITY OFFICER

This part is like that of the Chief Security Officer, yet concentrates all the more eagerly on ensuring an association’s information and protected innovation – the data related resources. CISO obligations normally incorporate keeping up best practices and outlining compelling arrangements to handle ruptures and different debacles. Normal Salary: $192,500.

6. DIGITAL SECURITY LEAD

A Cyber security Lead has an especially requesting and high-weight employment: assessing the association for potential vulnerabilities in conjunction with investigators and other security staff, identifying any assaults in progress and illuminating administration. Normal Salary: $175,000

7. LEAD SECURITY ENGINEERS

Lead Security Engineers can be tasked with numerous obligations, contingent upon their association: securing working situations, telephony and feature gathering frameworks and programming, equipment and data. Normal Salary: $174,375
8. COMPUTER FORENSICS EXPERT

A Computer Forensics Expert is in charge of breaking down proof assembled off of PCs, systems and other information stockpiling gadgets with an end goal to explore occurrences of cyber crime. These people ordinarily work mostly with law implementation organizations to incorporate proof for legitimate cases, draft specialized reports or offer master affirmation in trial. A mixture of associations, including law implementation, legitimate firms and all levels of government, are the most widely recognized businesses of Computer Forensics Experts. These Experts make a middle pay of $77,270. They can hope to procure at any rate $56,000, as indicated by the PayScale.

9. MALWARE ANALYST

A Malware Analyst is in charge of helping an association comprehend the infections, worms, bots, Trojans and different pernicious programming that debilitate its system consistently. Malware Analysts normally work with Computer Forensics Experts in the occasion of an interruption and/or suspicious PC conduct to help recognize vindictive projects that may have penetrated an association’s PC frameworks. Malware Analysts make a middle compensation of $75,000. They can hope to win in any event $48,000, however some can take home as much as $100,000 a year.

10. SECURITY SPECIALIST

A Security Specialist is a passage to mid-level worker who is in charge of finishing a mixed bag of obligations intended to reinforce the security of an association. Security Specialists are obliged to dissect the security necessities of an association’s frameworks, introduce and design security arrangements on corporate systems, perform helplessness testing and help train kindred representatives in security mindfulness. Security Specialists make a middle pay of $73,853. As per PayScale’s latest gauges, these people can hope to make in any event $43,000 yet can plan to take home as much as $113,000.


Tuesday 16 June 2015

9 Must Read Articles For Programmers



We have long been talking about the ebooks that are must-read for designers and developers, but not much has been discussed about the articles that will make programmers learn a great deal. There are many developers/programmers that every now and then come up with the articles that focus on making their peer group learn and follow the easy steps to get the desired/aim at results.
So, for today we chose this topic to be talked about thereby helping you all with the websites where various useful articles have been published to help all your programmers out there the best way possible. I personally loved the topic of the day as I know it might be the best way out for many of you out there to learn miscellaneous things in a short span of time. Besides, if you are stuck somewhere, I guess checking these helpful articles written in simplest and easy understandable way will enlighten you by providing the best possible know-ho on the particular topic.
So, check must read programming articles and if you wish to go ahead reading them till the end, click on the link and go ahead. Also, do not forget to check out our other article featuring all the best free Machine Learning ebooks.

1. The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets

Written by Joel Spolsky founder of statckoverflow.com “The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)”  long back, this article promises to make developers learn smarter way. It easily makes them understand what is unicode, what is character encoding, how characters are represented using bytes and many more.

2. What should Every Programmer know about Security?

Security is a topic that ranges from encryption/decryption, SSL, web security, obfuscation, authentication, authorization and much more. If any of you programmer out there wants to learn the basic minimum knowledge, learn how to write exploit code, then this is the apt pick for you all. Without knowing how systems are exploited attaining knowledge about patching code is meaningless. Follow the secure Java coding practices provided by fortify, PMP and other static code analysis providers and learn everything about security.

3. What Every Web Developer must know about URL Encoding

Prepared by Stephane Epardaud, this write-up describes the common misconceptions about Uniform Resource Locator (URL) encoding. Also, it attempts to clarify URL encoding for HTTP, before presenting frequent problems and their solutions. One gets to learn the basics of URL grammar, general URL syntax in HTTP, other protocol and much more.

4. What Every Programmer Need to know about Game Networking

Ever wondered how multi-player games work sharing a consistent experience across the network? If yes, then his article would enlighten you with the possibilities programmers look for and work on. Its a must read for game programmers.

5. What Every Programmer should know about SEO

If you wish to know how search engines work then this is the article that you should definitely go about reading. The article provides all relevant information about basics of Search Engine Optimization in simple and easily understandable way.

6. What Every Programmer should know about Memory

Written back in 2007 this article is still a big hit for the fact that not all programmers have enough knowledge of memory which is important if you are into writing high performance application. Learn about RAM, CPU Caches, different types of memory, direct memory access, memory controller designs and Memory in general with this write-up.

7. 10 Things Every Java Programmer Should Know about String

String in Java is a important class, therefore it is of great importance to attain a good knowledge of different String functionalities. This article focuses on various important areas of String like string pool, string literal, comparing String using == vs equals(), converting bytes to String and everything you get to know to come up with the desired results.

8. Latency Numbers Every Programmer should know

This article makes programmers learn how to write a high performance application in any programming language e.g. Java or C++.

9. What Technical Details should a Programmer of a Web Application Consider before Making the Site Public

Going through this article will make programmers learn about various key technologies like HTTP, HTML, XML, CSS, JavaScript, browser compatibility, and ways of implementing the technical details of a web application consider before making the site public.
It is not always that one gets much time to check out ebooks and read them. The other best way to get useful information is by reading the articles that are dedicated to help all your programmers out there. If you have come up with any such helpful articles and wish to share with us, what’s the wait for then. Go ahead and leave your comments below.



Monday 15 June 2015

3 tools that techies are using to boost productivity


The tech team, a.k.a., the people who are always one step ahead of you when it comes to new apps, sites, and extensions. Or, I should say, the people who were one step ahead of you. After you check out this article on tools that they're regularly using, you'll feel like an insider, too.

But, before you dig in, know these aren't just three random things that techies are currently utilizing. They're specifically designed to make automating and streamlining tasks a whole lot easier. And that means you can get more work done than ever!

I heard that groan. So I'll tell you what it also means: You'll have time to sneak out a little bit earlier a few nights this summer and enjoy some of this beautiful, beautiful sunshine.

1. Gmail Labs

If you're like many of us on this fine planet, you currently use Gmail to get through your day. But, I bet you didn't know that you can play mad scientist with it. And no, I'm not talking about creating a Frankenstein-like mash-up between your pharmacy spam and that weekly accounting report, I'm talking about Gmail Labs.

Gmail Labs are special settings that add helpful features to your email. You can get started by going into your account, clicking the gear icon, then "Settings," then a tab on the right called "Labs." There you'll find what you need to transform your email into a more manageable creature.

There are several to choose from, but I suggest starting with a few of my favorites.

Undo Send

How many times have you noticed you forgot to attach a file or worse, made a typo, just two seconds after clicking send? With Undo Send, you can stop that message from going out, saving yourself embarrassment and time spent sending along a follow-up email that says, "Now this time, with the attachment attached, lol."

Canned Responses

Do you find yourself answering the same emails over and over again? Save time (and your wrists) by not re-typing repetitive messages. Instead, build yourself a bank of standard responses that you can send out whenever needed.

Unread Message Icon

Sometimes you're waiting for an important email to come in, but for one reason or another, you don't have time to keep opening up your inbox. With the Unread Message Icon, you can just glance at your Gmail browser tab and quickly see when it hits your inbox.

2. IFTTT

IFTTT, short for "If This, Then That," is a simple, but surprisingly powerful, automation tool that combines your favorite online services. Once you sign up for a free account, you can start creating recipes. Or as I call it, magic!
And creating recipes is a breeze. Just choose the cause (the "if") and the result you want (the "that"). For example, I want to make sure that I remember to return any calls I miss while I'm in meetings. So, one of my IFTTT recipes is: If I miss a phone call, add it to my to-do list. That means I don't have to worry any more that I'll forget to check my missed calls — because there's a reminder ready and waiting for me in my task manager.

What else can you do with IFTTT? That's somewhat up to your imagination. It currently lets you connect a fantastic number of online services, from Gmail to Slack to DropBox to Evernote, plus dozens and dozens more.

3. Workflow or Llama

Just because you're at work doesn't mean you should forget your phone as an automation tool. In fact, automating tasks on your phone can be one of the best ways to make your work life easier, especially if you're often away from your desk.
Workflow is a relative newcomer for iOS that's knocking the socks off of iPhone users around the world. It lets you easily combine functions or apps on your phone in a certain order. Combining them makes it possible to do manual things automatically.
Clever Workflow actions that you can set up once, and then use over and over, include turning a web page into a PDF, sending a message with your arrival time based on your current location, or reading text aloud to you.



Jealous of iPhone owners right now? Don't be.
Llama for Android has been around for years, yet it's flown under the radar. It also lets you work some magic on your phone with just a little minor set-up. You can have your phone silenced whenever you have a meeting scheduled on your calendar, instantly connect to your office Wi-Fi when you get to work, or pop up a reminder to stand and stretch once an hour.


All of these tools are easy to use, and they really can make a big dent in your daily to-do list. So, stop wasting your time doing needless work, and start using these to get finished with your work faster.

ReadMore




Sunday 14 June 2015

Is Facebook Going To Become The New Google


For close to two decades, Google has been the dominant online brand. It’s the name people turn to whenever they go to the web with a query. It provides maps, email, cloud storage, encyclopedic information entries, news, videos, operating systems, and countless other services—for free—to people around the world. Whether you judge it in terms of its technological sophistication, its authority and influence, its revenue-generating power, or just its scale, it is the preeminent force in the online world, and few companies can compete with it.


In terms of competitors, Bing and Yahoo are the only real brands that come to mind. Together, they account for less than a third of all search traffic, and most people don’t give them a second thought because they aren’t nearly as sophisticated as Google and don’t have access to anywhere near the amount of resources that Google does....Read More

Friday 12 June 2015

Learning Enough Python to Land a Job


If you want a job programming in Python, prepare to do a lot of work beforehand. The language is easy to pick up, but you need to do more than just learn the basics; to get a job, you need to have a strong understanding of some pretty complex processes.
Python is a general-purpose language, which means it isn’t used for just one purpose such as Web development. Rather, it’s used in many different industries, and the industry in which you choose to work will determine how you actually learn the language.
For example, if you’re hired to write apps that interact with operating systems and monitor devices, you might not need to know how to use the Python modules for scientific and numerical programming. In a similar fashion, if you’re hired to write Python code that interacts with a MySQL database, then you won’t need to master 


how it works with CouchDB.
Therefore, I’m going to suggest that there are three levels to learning the basics of Python:
  • Learn the core language itself, such as the syntax and basic types; learn the difference between Python 2 and Python 3.
  • Learn the commonly used modules, and familiarize yourself with other modules.
  • Learn the bigger picture of software development with Python, such as including Python in a build process, using the pip package manager, and so on. This involves learning about different databases and other technology, depending on where you want to work.

True Beginners

At a basic level, Python is an easy language to learn and use. You can quickly learn how to create variables and loops, for example, and expand beyond that to tuples, lists, and dictionaries. Any Python newbie needs to know which types are immutable, which means an object of that type can’t be changed (answer: tuples and strings). With immutable types, the object’s value itself can’t change, but the variable containing the object can:

a = 'abc'

a = a.upper()
In the above example, the original string “abc” did not change, as strings can’t change; instead, we calculated a brand new string, “ABC,” and stored that back into the original variable. Knowing that sort of thing should be second nature to anyone who seeks to understand how Python works.
In addition, anyone learning Python should know how the language deals with object-oriented programming, and how to create classes and instantiate objects. It’s also important to know how to use exceptions and exception handlers, and how modules interact. (For key insights, I recommend you read and understand thePython Language Reference; if you’re ever unsure about syntax or how the language works, or are arguing with a coworker, that website will have the final word.)

The Python beginner must also know how Python 2 and Python 3 are different. Python 3 has been out for quite some time, but there are still a lot of projects that rely on Python 2. If you’re interviewing for a position, you’ll want to ask which Python they’re using; if you’re knowledgeable, you can then speak about the differences.

Slightly More Advanced


Once you’ve mastered some basic concepts, you can move on to slightly more advanced concepts. If you’re familiar with languages such as JavaScript, Python’s strong typing might surprise you; for example, you can’t just add “hello” to “10” to get “hello10.” (You’ll get an exception.) This is meant to prevent bugs in your code, and it means you’ll need to become very familiar with dynamic typing, strong typing, duck typing, and how Python implements all three.

C++ programmers coming to Python might be surprised that you don’t need to provide an interface for a parameter in a function; if the object passed in has the required methods, you’re good to go. This makes polymorphism easy.
From there, it’s important to know about closures and “first class objects.” Python supports both, which leads to a concept called decorators, which this article explains very well. Here’s an interesting example of closures, modified from one offered in the linked article; this is entered from the interactive shell:




>>> def outer(x):

...     y = x * 2

...     def inner(z):

...         return y + z

...     return inner

...

>>> q = outer(5)

>>> r = outer(6)

>>> q(2)

12

>>> q(3)

13

>>> r(2)

14

>>> r(3)

15

>>>



The function outer creates a closure with the variable called y, and returns a new function that you can call. I called the outer function twice to create two such functions; then I called those two functions each twice.
Last but certainly not least: Read “The Zen of Python,” which is funny and real, and check out this thread on Stack Overflow for some great suggestions about how to master the language. Go to GitHub and find any of the many popular Python projects; study the code as much as you can.


Side Note: Learn the Modules

The modules are your libraries, your helpers. Know what’s available in the standard library; you don’t have to memorize every member of every class, and every class of every module, but you do want to know what’s available so that when you need something, you don’t go rewrite one from scratch.

Familiarize yourself with each module. Many, such as file I/O, have access in almost every application; know these inside and out. For example, know how to open a file with different access, how to read a file, how to write a file, and how to determine if a file or directory exists. Know how to use the os.path module for file-path joining and normalization, rather than writing your own string routines to handle file paths. Finally, understand the cross-platform implications.



Next: Learn Software Development With Python


There are many tools for integrating Python into a software development cycle. If you want to master the language in a real-world context, learn how to obtain Python packages using pip. You should also learn how to do unit testing, which is fundamental to software development in Python; many people get turned down for Python-related jobs because they can’t answer interview questions in this area. (The Hitchhiker’s Guide to Python includes some great information on unit testing.)
You should also know how to package up Python programs for distribution, and know your way around both the Windows command prompt and Linux bash shell. Any developer worth their salt can use the tools for general software development, from editors and IDEs to git for source-code control.

Targeting an Industry or Technology

Once you’re familiar with all the above, you can begin to move into industry-specific knowledge.
If writing C or C++ extensions to Python interests you, check out this resource. If Web development tickles your fancy, you’ll need to understand the difference between a Web server written in Python that you can extend, and a Web frameworkthat allows you to write your own server software in Python. If you go the Web route, you’ll need to become proficient in Web technologies—not only other languages such as JavaScript, but how to develop Web-scalable software.

There’s also some crossover between specializations. For example, if you’re building Web server software in Python that runs on a cloud, you might need to know how to build cloud-monitoring and management tools (possibly in Python as well). Those tools include Amazon AWS SDK for Python, or the OpenStack’s official clients, which are also written in Python.
If you want to land a job in a scientific industry, you’ll need to know the various scientific and numerical modules inside and out, and have strong skills in writing tight algorithms. For jobs in high-performance computing, you need skills such as concurrent algorithms, SIMD vectorization and multicore programming. For a full list of how to use Python in a work context, check out the dedicated page for applications for the language.


ReadMore